How should I query one of “comments” in a record? Why can’t you query through “_id”?
{
"_id": "56fa1c5acb169bd213e485de",
"title": "reach js learning notes",
"classify": "js",
"desc": "React is a JavaScript library file",
"author": "root",
"body": "",
"hidden": false,
"meta": {
"votes": 0,
"favs": 0
},
"date": "2016-03-30T08:20:36.866Z",
"comments": [
{
"body": "aaaa",
"date": "2016-03-30T08:43:50.401Z",
"guest": "A",
"email": "xxxxxx@qq.com",
"browser": "chrome",
"_id": "56fb91c6c4b8801709aec38a"
},
{
"_id": "56fb93ddc4b8801709aec38b",
"browser": "chrome",
"email": "xxxxxx@icloud.com",
"guest": "tester",
"date": "2016-03-30T08:52:45.445Z",
"body": "bbbbb"
}
],
"__v": 0
}
The most direct query:
db.collection.find( { _id:ObjectId("56fa1c5acb169bd213e485de") } )
Then obj.comments.body is directly called in the returned object.