mongodb自带的函数非常多,最近用mongo做持久化数据库,遇到一个需求:子文档是个数组,把数组里的各个字段扁平化合到根文档中,查过资料后(主要是mongodb的文档和stackoverflow)写出了下面的语句

 db.getCollection('table').aggregate
([ {$match:{"a" : {$gt:"2018-01-01 08:24:35"}}},
{ $unwind: {path: '$fillDocArray(subDoc)'}},
{ $project: { 'b':1,
'c':1,
'd':1,
'e': 1,
another_a: '$subDoc.subfield1',
another_b:'$subDoc.subfield'} }
])
05-11 13:14