Hello everyone! I want to create a table filled with the stores in my db. In the row I also want to display the total amount of clicks. The clicks are however on the deals collection. How can i solve this?
deals example (will be many different deals document for the store): {
"_id": {
"$oid": "63944bb38ac849ba16eb01d3"
},
"description": "Save 11%",
"store": {
"$oid": "639449e63234220ad3e22642"
},
"clicks": 10
}
Thanks for this! It did work but seems like it added some unecessary stuff in there? I ended up asking Co-pilot and it actually managed to give me exactly what i wanted:
Notes that your version will use more memory, since all the deals are kept from the $lookup until your final $project. By counting, the clicks in the pipeline of the $lookup, just the count is kept. Keeping all the deals inside the store object until the final $project increases the chances to get the 16Mb limit on object size.
The following can simply be used in your final $project to remove the extra stuff.