Reputation: 1611
I'm trying to pull a document from a Meteor collection without the _id field but neither inclusion:
Db.find({foo: bar}, {fields: {
test1: 1,
test2: 1,
_id: 0
}})
nor exclusion:
Db.find({foo: bar}, {fields: {
test3: 0,
_id: 0
}})
seem to work. Both just return an empty array. I know pulling a document with the _id excluded is possible in Mongo, is it in Meteor?
Upvotes: 4
Views: 2819
Reputation: 831
I think you have forgotten some braces:
Db.find({
foo: bar
}, {
fields: {
test3: 0,
_id: 0
}
});
And i have read somewhere, that the mix of inclusion/exclusion is not supported. This means, that your first example will not work.
EDIT:
From the meteor docs:
Field Specifiers
On the server, queries can specify a particular 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 the 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 only includes the specified field, use 1 as the value. The _id field is still included in the result.
Users.find({}, {fields: {firstname: 1, lastname: 1}})
It is not possible to mix inclusion and exclusion styles.
Upvotes: 3