mongo 数组元素检索与排序

Posted 夜未央丿

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mongo 数组元素检索与排序相关的知识,希望对你有一定的参考价值。

db.getCollection(‘test‘).aggregate([
  {‘$match‘: {‘codes.name‘: ‘a‘}}, // 检索文档
  {$unwind: "$codes"},             // 拆分数组
  {‘$match‘: {‘codes.name‘: ‘a‘}}, // 检索数组元素
  {‘$sort‘: {‘codes._id‘: -1}},
  {‘$skip‘: 2},
  {‘$limit‘: 3} 
])

 

以上是关于mongo 数组元素检索与排序的主要内容,如果未能解决你的问题,请参考以下文章