MongoDB查询问题
阿神
阿神 2017-05-02 09:19:55
0
2
515

条件:如果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"
}
阿神
阿神

闭关修行中......

reply all(2)
左手右手慢动作

db.table.find('comment.username', "Fail")

阿神

Suppose the name of the collection is comment, it should be
db.comment.find({'comments.username', 'Faith'});

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template