0
回答
mongodb 内嵌数组查询问题: 如何限定返回与条件匹配的数组
开发十年,就只剩下这套Java开发体系了   



原数据为:


{
    "_id" : NumberLong(1181675746),
    "shard_qty" : 2,
    "goods_qty" : 0,
    "shop_qty" : 0,
    "favorite_qty" : 2,
    "favorite_shards" : [ 
        {
            "sid" : NumberLong(578),
            "favorite_dt" : ISODate("2015-06-26T12:13:06.405+08:00"),
            "is_attention" : true
        }, 
        {
            "sid" : NumberLong(577),
            "favorite_dt" : ISODate("2015-06-26T13:20:48.449+08:00"),
            "is_attention" : true
        }
    ]
}


查询条件为

db.getCollection('web_mem_favorites').findOne(
{'_id':NumberLong(1181675746),'favorite_shards.sid': {'$in':[NumberLong(577)]}}
,{"favorite_shards":1}
)





想返回的数据:


{
    "_id" : NumberLong(1181675746),
    "favorite_shards" : [ 
        {
            "sid" : NumberLong(577),
            "favorite_dt" : ISODate("2015-06-26T13:20:48.449+08:00"),
            "is_attention" : true
        }
    ]
}





举报
筱龙缘
发帖于3年前 0回/1K+阅
顶部