Is there any way to carry out the following operation in just one $project stage?
$project
db.getCollection(\'users\').aggregate([ { $project
You need $let operator:
db.getCollection('users').aggregate([ { $project : { domain : { $let: { vars: { firstEmail: { $arrayElemAt : ["$emails", 0] } }, in: "$$firstEmail.domain" } } } } ])
Mongo Playground