MongoDB查詢問題
阿神
阿神 2017-05-02 09:19:55
0
2
511

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

闭关修行中......

全部回覆(2)
左手右手慢动作

db.table.find('comment.username', "失敗")

阿神

假設collection的名字是comment,應該是
db.comment.find({'comments.username', 'Faith'});

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板