MongoDB relationships: embed or reference? -


I am new to mongodibi - coming from a relational database background. I want to create a question structure with some comments, but I do not know which relationship to use: embed or context ?

A question with some comments, such as, would be such an structure:

  question title = 'aaa' content = bbb 'comments = ??? First of all, I want to use embedded annotations (I think the  embed  is suggested in MongoDB), such as: 

< Pre = AAA content = 'BBB' comment = [[content = 'xxx', created = 'yyy'}, {content = 'xxx', created = 'yyy'}, { Content = 'xxx', it is clear, but I am worried about this matter: If I want to edit a specific comment, Mr. How do I get and how to get his question could /? ? I do not have any _id to allow me to find my question, neither do I question_f (I'm so newbie, I do not know if _id < / Code> and question_ref .)

Do I have ref not embed to use? Then I have to create a new collection for comments?

It is more art than science. It is a good reference, but here to consider something Things are:

  • Keep as much as possible

    The pleasure of a document database is that it eliminates many involved your first trend is to Keep the same in the document as much as you can. Since MongoDB is the structure of documents, and because you can efficiently query within that structure (it means that you can take part of the document that you need, so the document size should not be of much concern to you). There is no urgent need to normalize the data. You will be in SQL, especially any data that is not useful to its original documents. Must be a part of the document.

  • Different data that can be referenced in many places from your collection.

    This is not a "storage space" problem because it is the "data sustainability" issue, if multiple records refer to the same data, then it would be necessary to update another record and keep references to other locations. Efficient and low error appears.

  • Ideas of document size

    MongodiBi sets a 4 MB (16 MB to 1.8) size limit on a document. It seems small in the world of GB data, but it also has 30 million tweets or 250 thousand typical stack overflow answers or 20 flicker photos. On the other hand, it may want to present more than one at a specific web page at one time, there is much more information than this. First consider whether will make your questions easier. In many cases concerns about the size of the document will be optimized prematurely.

  • Complex data structures:

    Mongodi arbitrarily can store deep nested data structures, but can not find them efficiently. If your data creates a tree, forest or graph, then you need to store each node and its edges in a separate document. (Note that the data store is designed specifically for this type of data that anyone should consider)

    Apart from this, it is also impossible to return a subset of the elements of the document is. If you need to select and select each document, it will be easy to separate them.

  • Data Compatibility

    MangoDebbi creates a trade-off rule between efficiency and stability is a document change always atom, while many documents Update should not be assumed to be atomic. There is no way to "lock" a record on the server (using the "lock" field, for example, you can create it in the client's logic). When you prepare your schema, think about how you will maintain your data consistently, the more you keep a good deal in a document.

I will embed comments that you are describing, and each comment has an object id. Object ID has a time stamp, so that you can use it instead of being used on it.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

c# - Create dynamic LINQ query expression at runtime which translates into a parameterized SQL query for nullable types -

cmake - cpack generates RPMs with %files entries that conflict with the RPM spec. How to fix? -