I am trying to figure out how I can get a list of related tags from blog posts stored in MongoDB.
Data structure
{ title: "Post #1", tags: { "news", "politics" } }, { title: "Post #2", tags: { "news", "entertainment" } }, { title: "Post #3", tags: { "entertainment", "music", "theatre" } }, { title: "Post #4", tags: { "entertainment", "music", "concerts" } }
Desired Result
If I want to get a list of tags related to "entertainment", it asks for messages to find similar tags. Similar tags are those that are also used when the message is marked as "entertainment."
I would like to get the following result:
Tag Count
Is there a way to get as close to this as possible? The closest I managed to get is to use db.posts.find({tags: "entertainment"}); and then loop through and build these values outside of MongoDb. I am looking for a more efficient way.
source share