Is there any way to carry out the following operation in just one $project stage?
$project
db.getCollection(\'users\').aggregate([ { $project
When working with array of objects, you can automatically get array of objects's properties with the dot notation. So the following will perfectly work :
db.getCollection('users').aggregate([ { $project : { domain: { $arrayElemAt : ["$emails.domain", 0] } } }, ])
Mongo playground