mongoDB查詢數組中的數組
PHPz
PHPz 2017-04-28 09:06:22
0
1
637
{ "_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的前兩個字段,要怎麼做?

PHPz
PHPz

学习是最好的投资!

全部回覆 (1)
小小卫

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

    最新下載
    更多>
    網站特效
    網站源碼
    網站素材
    前端模板
    關於我們 免責聲明 Sitemap
    PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!