mongoDB内嵌文档返回匹配的数组元素
使用$unwind,用于分割内嵌数组
适合情况:条件不唯一,查询多个
例子:
db.collection.aggregate([{'$unwind': '$arr1'}, {'$unwind': '$arr1.arr2'}, {'$match': {'arr1.arr2.field': 'value'}}])
处理多重嵌套的基本思路:提取、拆分、匹配
使用$unwind,用于分割内嵌数组
适合情况:条件不唯一,查询多个
例子:
db.collection.aggregate([{'$unwind': '$arr1'}, {'$unwind': '$arr1.arr2'}, {'$match': {'arr1.arr2.field': 'value'}}])
处理多重嵌套的基本思路:提取、拆分、匹配