Return only specific fields from projection array sub-document

后端 未结 1 1174
囚心锁ツ
囚心锁ツ 2021-02-05 20:45

I\'m looking at MongoDB\'s documentation on the $ and $elemMatch projections. I\'m trying to figure out how to return only a subset of a projection array\'s fields, but I canno

相关标签:
1条回答
  • 2021-02-05 21:27

    Are you specifically trying to do this without using aggregate?

    db.test.aggregate([{$unwind:"$array"},
                       {$match:{"array.key":1}},
                       {$project:{"array.name":1, extra:1}}])
    
    0 讨论(0)
提交回复
热议问题