smile_elims

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

db.T_Forum_Thread.find({ "ThreadReply.ReplyContent" : /范甘迪/ }, { "ThreadReply.$" : 1, "ThreadContent" : 1 })

 

重点在于返回字段:ThreadReply.$:1

 

如果内嵌的数组有多个符合条件只返回了1条,,,待继续深究

 

db.test.aggregate(
    {"$unwind":"$favorite_shards"}, 
    {"$match":
        {"favorite_shards.sid": 
            {"$in": [NumberLong(578), NumberLong(577)]}
        }
    }, 
    {"$group":
         {"_id": "$_id", "favorite_shards":
            {'$push': "$favorite_shards"}
        }
    })     


db.web_mem_favorites.aggregate( {"$project":{"favorite_shards":"$favorite_shards"}}, {"$unwind":"$favorite_shards"}, {"$match":{"favorite_shards.sid": NumberLong(577)}} )

 



posted on 2016-05-20 14:53  smile_elims  阅读(510)  评论(0编辑  收藏  举报