I am just trying to get into mongo (,couch or nosql in general), and started with good old blog example. From what I read on the mongo page entities should be put in a separate collection when there is the need for direct access, so I put comments and users within the posts-collection and have another collection for the categories.
My question is where to place the tags. I saw in some examples, that there were placed in the post collection as well, but I am not sure how to easily create a tag-cloud then
as mentioned: this is just for learning purpose..
thanks! harpax
You can store the tags in your document and then run an aggregate query on your documents to get the cloud ...
However, I'd think the best idea would be to run a query (on a schedule) to build your tag cloud as it's own document ... that way you can simple just query that document to build your list (instead of trying to run that on the fly each time.)
There is a great example of how to do this here.
http://cookbook.mongodb.org/patterns/count_tags/
Example Document
{
"title" : "A blog post",
"author" : "Kristina",
"content" : "...",
"tags" : ["MongoDB", "Map/Reduce", "Recipe"]
}
Example Cloud
{"_id" : "MongoDB", "value" : 4}
{"_id" : "Map/Reduce", "value" : 2}
{"_id" : "Recipe", "value" : 7}
{"_id" : "Group", "value" : 1}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With