drevicko
drevicko

Reputation: 15180

Does mongodb's find() return objects missing a field from the specified projection?

If I have a mongodb containing this:

{ _id:ObjectId(0), name:"foo", hits:5 }

Will it get returned by this query:

find({name:"foo"}, {hits:1, flow:1})

If so, what will the returned object look like?

Upvotes: 1

Views: 314

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 311975

Yes it will, and it will look like this:

{ "_id": ObjectId("000000000000000000000000"), "hits": 5 }

name is omitted because it's not included in the projection, but _id is included by default.

Upvotes: 3

Related Questions