mongodb 内嵌文档查询
发布于 10 年前 作者 babata 6700 次浏览 最后一次编辑是 8 年前

{ “shellList”: [ { “bookId”: “168”, “readPagePercent”: “0”, “createTime”: “2014-01-21 16:17:33”, “readType”: “1” }, { “bookId”: “168”, “readPagePercent”: “2”, “createTime”: “2014-02-21 16:17:33”, “readType”: “2” } , { “bookId”: “169”, “readPagePercent”: “2”, “createTime”: “2014-02-21 16:17:33”, “readType”: “2” } , { “bookId”: “170”, “readPagePercent”: “2”, “createTime”: “2014-02-21 16:17:33”, “readType”: “2” } ], “userId”: “100002” } 我怎查出 bookid为168的文档呢 求指导

1 回复

db.collection.find({},{‘shellList’:{$elemMatch:{‘bookId’:‘168’}}})只能查出一条 但是我希望符合条件的都查出来,好诡异的查询。 mongodb 有个$slice ,可以把数组劈开,既然这样可以,那应该有条件查询相关的解决方法

回到顶部