suchen

Heim  >  Fragen und Antworten  >  Hauptteil

MongoDB查询问题

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

Antworte allen(2)Ich werde antworten

  • ringa_lee

    ringa_lee2017-05-02 09:21:55

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

    Antwort
    0
  • 阿神

    阿神2017-05-02 09:21:55

    假设collection的名字是comment,应该是
    db.comment.find({'comments.username', 'Faith'});

    Antwort
    0
  • StornierenAntwort