搜尋

首頁  >  問答  >  主體

mongoDB查詢數組中的數組

{
    "_id" : "1249",
    "auth" : {
        "_id" : "admin",
        "name" : "admin"
    },
    "content" : "亡官方的冷漠反应",
    "title" : "在上海一家外企工作。",
    "theme" : "bug",
    "dtype" : "all",
    "reply" : [ 
        {
            "discussname" : {
                "_id" : "wzb",
                "name" : "wzb"
            },
            "content" : "\t无言",
            "createtime" : ISODate("2004-08-03T15:05:00.000Z"),
            "floor" : "1",
            "reply" : [ 
                {
                    "replyname" : {
                        "_id" : "123",
                        "name" : "123"
                    },
                    "author" : "",
                    "content" : "不错哦",
                    "createtime" : ISODate("2016-01-13T08:08:10.081Z")
                }, 
                {
                    "replyname" : {
                        "_id" : "123",
                        "name" : "123"
                    },
                    "author" : "",
                    "content" : "jiayouo",
                    "createtime" : ISODate("2016-01-13T09:27:10.881Z")
                }, 
                {
                    "replyname" : {
                        "_id" : "123",
                        "name" : "123"
                    },
                    "author" : "回复 123",
                    "content" : "nihao",
                    "createtime" : ISODate("2016-01-13T09:27:25.681Z")
                }]
        },{
            "discussname" : {
                "_id" : "123",
                "name" : "123"
            },
            "floor" : "2",
            "content" : "好帅",
            "createtime" : ISODate("2016-01-16T11:04:07.917Z"),
            "reply" : [ 
                {
                    "replyname" : {
                        "_id" : "123",
                        "name" : "123"
                    },
                    "author" : "",
                    "content" : "很好",
                    "createtime" : ISODate("2016-01-16T11:05:21.036Z")
                }
            ]
        }
 }

像上面的字段,我這樣查詢:

db.getCollection('tribune').find({"_id":"1249"},{"reply":{"$elemMatch":{"floor":"1"}}})

取出來的裡面的reply數組(就叫 A 吧),現在我想取數組A的前兩個字段,要怎麼做?

PHPzPHPz2797 天前752

全部回覆(1)我來回復

  • 小小卫

    小小卫2017-09-23 10:25:52

    沒豆豆了  打擾了沒豆豆了  打擾了沒豆豆了  打擾了沒豆豆了  打擾了沒豆豆了  打擾了沒豆豆了  打擾了沒豆豆了  打擾了

    回覆
    0
  • 取消回覆