条件:如果comments里面的所有username,只要有一条等于xxx(比如:Faith)的,就返回整条记录
{
"_id": ObjectId("5780913bc3666e25282ffdb0"),
"description": "xx",
"readed": 2,
"type": "1",
"content": "<p>xx</p>",
"list_img": "xx",
"comments": [
{
"username": "Faith",
"content": "bbb",
"avatar": "/static/images/steam_avatar.jpg",
"sendtime": "2016-07-09 05:53:04"
},
{
"username": "Faith",
"content": "ccc",
"avatar": "/static/images/steam_avatar.jpg",
"sendtime": "2016-07-09 05:53:04"
},
{
"username": "123",
"content": "zzz",
"avatar": "/static/images/steam_avatar.jpg",
"sendtime": "2016-07-09 05:53:04"
}
],
"author": "admin",
"sendtime": "2016-07-09 05:52:59",
"title": "xx"
}
db.table.find('comment.username', "失敗")
コレクションの名前が comment であるとすると、
となります。db.comment.find({'comments.username', 'Faith'});