Meteor: how can I return data from fields in a specific object?

This should be pretty simple.

myobjecthas various properties, _id, name, createdBy, dateetc.

In my search query, I only want to return specific fields from myObject. So, for example, what do I need to do to change the search query below to return only name?

myCollection.find({createdBy: someId}, {fields: {myObject: 1}}).fetch();

Currently, this will return everything to myobjectwhat it should do, I just need to return one field inside myobject.

+1
source share
2 answers

Here's how to do it in the request:

myCollection.find ({createdBy: someId}, {fields: {'myObject.name': 1}}) fetch () ;.

Pay attention to the quotes around.

'myObject.name'

+2
source

, , :

{
  _id: 'abc123',
  title: 'All about meteor',
  author: {
    firstName: 'David',
    lastName: 'Weldon'
  }
}

:

var lastNames = Posts.find().map(function(post) {
  return post.author.lastName;
});

, . fields , .

+1

All Articles