Shantanu Gupta
Shantanu Gupta

Reputation: 21108

MongoDb query not returning all the fields

Why following statement is not returning me all the fields from collection in mongoDb

db.post.find({"ppu":0.55}, {$or : [{"name":"Cake"}, {"name":"Raised"}]})

This is returning me just an objectId column _id not all the fields.

Upvotes: 1

Views: 1575

Answers (2)

mnemosyn
mnemosyn

Reputation: 46341

The syntax of find is:

db.collection.find(<criteria>, <projection>)

So your second parameter should be a projection, but it's not. What the projection looks like is explained very well in the docs.

Upvotes: 4

Sede
Sede

Reputation: 61293

db.post.find({"ppu":0.55}, {$or : [{"name":"Cake"}, {"name":"Raised"}]})
                        ^

Change your query to the following because the second argument to the find method should be a projection which it is not in your case

db.post.find({"ppu":0.55, $or : [{"name":"Cake"}, {"name":"Raised"}]})

Upvotes: 3

Related Questions