mongodb子文档查询

--子文档分页

-- 测试数据

db.childTests.insert({ "_id" : 1, "item" : "ABC", "sizes": [ {age: 10, name:"susan"}, {age:11, name:"sandy"}] })
db.childTests.insert({ "_id" : 2, "item" : "ABC", "sizes": [ {age: 12, name:"Billy"}, {age:13, name:"Sam"}] })


--分页语句,从索引1开始,取两条数据

db.childTests.aggregate( [
{ $unwind: "$sizes" },
{$match: {"sizes.age":{$gte:11}}},
{$skip: 1},
{$limit: 2} ] )

 

 

posted @ 2016-06-23 20:28  無限大  阅读(2160)  评论(0编辑  收藏  举报