条件:如果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"
}
阿神2017-05-02 09:21:55
컬렉션 이름이 comment라고 가정하면
db.comment.find({'comments.username', 'Faith'});