知识别:
1,MongoDB 聚合
MongoDB中聚合(aggregate)主要用于处理数据(诸如统计平均值,求和等),并返回计算后的数据结果。有点类似sql语句中的 count(*)。
2,文档
https://mongoing.com/docs/meta/aggregation-quick-reference.html
db.getCollection('book').aggregate([
{$match: {_id: ObjectId("5efc60a727b87c6254d0bb7b")}},
{$project: {cp: 'project: {_id: 0, chapter: '$chapter'}},
{$unwind: '$cp'},
{$unwind: '$cp'},
//{$match: {}}
])
// 取第100章 这一条记录
db.getCollection('book').aggregate([
{$match: {_id: ObjectId("5f0c0dd3313784479c22602d")}},
{$unwind: 'skip : 100 },
{ $limit: 1}
])