Reputation: 1229
I am new to MongoDB
and Im trying to write a query to extract data from a collection I created but I am stuck in trying to do so. Any help would be greatly appreciated.
I want to get all the fields except _id
for all movies that are NOT based on things
How could I do this in a MongoDB query? I've read and looked up many things trying to learn about Mongo but so far I haven't gotten anything. Thank you very much in advance.
This is my collection:
{ "_id" : ObjectId("5363738hhhe2282828282w"), "coll" : "PageMaster" }
{ "_id" : ObjectId("0000222211223333sssswq2"), "coll" : "Honey1", "Jink" : { "head" : "Jink1"} }
{ "_id" : ObjectId("5hjkwwowwj7373365252wwww"), "coll" : "Rodger", "things" : { "head": "Honey"} }
Upvotes: 2
Views: 59
Reputation: 19700
Just check for the records where the key BOOK
does not exist
. Those are the records that we want. And exclude the _id
field in the projection parameter.
db.MOVI.find({"BOOK":{$exists:false}},{"_id":0})
EDIT:
For using printjson
to print the cursor contents:
var myCursor = db.MOVI.find({"BOOK":{$exists:false}},{"_id":0});
myCursor.forEach(function(doc)
{
printjson(doc);
})
Upvotes: 2