Hello I have just started working with mongo and am trying to run a basic find() command.
I have a collection that has records that look like this:
{
"event" : "cheat",
"message" : {
"tableid" : 205,
"time" : 1381853433038,
"link" : "/dbcheat/table205/iID3731"
},
"_id" : ObjectId("525d68f999ddc6a019000004")
}
I would like to find all of the entries that have tableid 205 for example. If I run this command I get back the one row.
db.example.find({
"message" : {
"tableid" : 205,
"time" : 1381853433038,
"link" : "/dbcheat/table205/iID3731"
}
})
But if I just try and run this command I get returned zero results. Does anyone know what could be the issue?
db.example.find({
"message" : {
"tableid" : 205
}
})
You should be able to locate the desired document by doing the following:
db.example.find({ "message.tableid": 205 })
The dot notation like in the reply from thtsigma allows you to reach into embedded documents and search. The 2nd way you were trying is saying bring back an embedded document for message that has "only" the following: "tableid" : 205
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With