Excluding _id from a Meteor search query?

I am trying to pull a document from the Meteor collection without the _id field, but not including:

Db.find({foo: bar}, {fields: { test1: 1, test2: 1, _id: 0 }}) 

and exception:

 Db.find({foo: bar}, {fields: { test3: 0, _id: 0 }}) 

seems to work. Both just return an empty array. I know that it is possible to pull out a document with excluded _id in Mongo, is it in Meteor?

+4
source share
1 answer

I think you forgot some braces:

 Db.find({ foo: bar }, { fields: { test3: 0, _id: 0 } }); 

And I read somewhere that the inclusion / exclusion combination is not supported . This means that your first example will not work.

EDIT:

From the meteor docs :

Field Qualifiers

On the server, queries can specify a specific set of fields to include or exclude from the result object. (The field specifier is currently ignored on the client.)

To exclude certain fields from result objects, the field specifier is a dictionary whose keys are field names and whose values ​​are 0.

Users.find({}, {fields: {password: 0, hash: 0}})

To return an object that includes only the specified field, use 1 as Value. The _id field is still included in the result.

Users.find({}, {fields: {firstname: 1, lastname: 1}})

You cannot mix inclusion and exclusion styles.

+3
source

All Articles