Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a schema the mongo/nosql way

Tags:

mongodb

nosql

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

like image 519
harpax Avatar asked Jan 18 '11 20:01

harpax


1 Answers

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}
like image 170
Justin Jenkins Avatar answered Oct 28 '22 13:10

Justin Jenkins