Thatstamil

[Solved] Thatstamil | Basic - Code Explorer | yomemimo.com
Question : thatstamil

Answered by : naughty-nightingale-oetedu6frhs0

db.test.aggregate([ // Get just the docs that contain a shapes element where color is 'red' {$match: {'shapes.color': 'red'}}, {$project: { shapes: {$filter: { input: '$shapes', as: 'shape', cond: {$eq: ['$$shape.color', 'red']} }}, _id: 0 }}
])

Source : https://stackoverflow.com/questions/3985214/retrieve-only-the-queried-element-in-an-object-array-in-mongodb-collection | Last Update : Wed, 05 Aug 20

Answers related to thatstamil

Code Explorer Popular Question For Basic