Query deep level nested documents with top level document id
You will have wrap it _id with ObjectId()
and createdAt with ISODate('')
. I don't know why it is not working in mongoplayground
db.collection.aggregate([ { $match: { _id: "5a2ca2227c42ad67682731d4" } }, { $unwind: "$departments" }, { $unwind: "$departments.projects" }, { $match: { "departments.projects.createdAt": { $gte: "2021-04-09T00:00:00Z" } } }])
MongoPlayground: https://mongoplayground.net/p/Qll_t6RBltL