Being new to MongoDB I’m not really sure what would be the best practice for this.
Currently Posts have a set of tags assigned to them, and I’d like to include at the bottom of each post a “Related Posts” section. What would be the different/best way(s) to accomplish this in MongoDB?
My initial guess is that I would scan for which posts have ANY of the parent post’s tags, then I’d cycle through the posts and count how many of the parent post’s tags they have. The ones that have the highest amount of same tags would be first. Though this seems incredibly ineffecient.
Thanks guys, I ended up storing the related documents inside the parent document.
To find related documents, I found all which have ANY of the parent document tags, then sort by how many tags they mutually have.
Here is the logic:
https://github.com/bevry/docpad/blob/2bcfd152b4b55bab8944c968b8bf093300925319/lib/docpad.coffee#L297
Here is the schema:
https://github.com/bevry/docpad/blob/2bcfd152b4b55bab8944c968b8bf093300925319/lib/docpad.coffee#L85