I have a question about querying nested documents. I tried to search but nothing answered my question or I am maybe overlooking it. I have structure like this:
According to above mentioned description please try executing following query in MongoDB shell.
db.collection.aggregate( // Pipeline [ // Stage 1 { $unwind: "$books" }, // Stage 2 { $group: { _id:null, books:{$addToSet:'$books'} } }, // Stage 3 { $project: { books:1, _id:0 } }, ] );