Reputation: 13654
basically I have a list of posts, and I am wondering if I need a separate collection of links to those posts. Of course I want to show the postname in my abbreviated list (and on mousehover the content too), but querying for the postname and content would load all comments too right? (because they are embedded. The comments array is expected to be significantly larger than the post 'Content')
Is there any way I can avoid getting another collection but at the same time avoid loading the comments each time I want to know the name/description of a post?
> db.Posts.find()
{
"_id" : "123",
"Name": "test",
"Content": "wooops",
"comments" : [ {comment1}, {comment2}, {comment3} ]
}
Of course, I am aware that I can just create another collection for the comments. But as far as I can tell that won't be possible in production use, because I expect to have a lot of posts each day, which means that each new post would create a new comments collection. Is this recommended? As far as the official docs say, the max collection number is 12000. Even though it says that the number can be increased, I get the strong feeling that this wouldn't be a good idea. edit: I calculated it, the absolute maximum is 1.5million collections/=posts. Which is not enough of course.
Any experiences on this matter would be greatly appreciated :)
Upvotes: 0
Views: 81
Reputation: 262814
but querying for the postname and content would load all comments too right?
Not necessarily. MongoDB lets you load partial documents (similar to a projection in SQL, where you SELECT only some fields) To do this, you add a second argument to the find() query, supplying a document that lists the elements to be returned:
> db.Posts.find({}, {Name:true, Content:true})
Upvotes: 1