norm - Mongo one to many relation and update problems -
I am implementing a blog based on MongoDB.
We first see how Mongo people advise us to store a blog post and comment on it ():
- The post should be a collection. Comments should be embedded in a post to display.
I came to know that it is very difficult to accept the comment in this schema.
Due to the comment, a part of the post document, I can not edit it separately because there is no identifier to find in the comment archive.
This is the reason why I am editing all the comments together. Another problem is that whenever I can post a new comment, then I am editing all the comments and this commentary collection After saving it will be overridden.
Am I doing something wrong? Or the use case described by people of Mongo is expected that the comments will not be edited.
Regards, Alexei Zakrowov
You should be able to "save all comments" I should be able to use the surroundings. For example, something like this should be done:
db.posts.update ({_id: [ID]}, {$ set: { "Comments.5.body": "New Comment Body"}}
Edit: Just like to expand on the answer given above Nuclear operators work only from those specific fields (which you THEY say) to meet, rather than the entire document. This not only makes your updates more intuitive but it is also very fast. Especially if, in your example, you have a big blog post with many comments.
Comments
Post a Comment