MongoDB preferred schema for embedded collections. documents vs. arrays

前端 未结 2 1364
粉色の甜心
粉色の甜心 2021-01-31 05:22

I believe there at least two ways to have embedded data in a mongodb document. In a simplified case we could have something like this:

{
    \'name\' : \'bill\',         


        
2条回答
  •  醉梦人生
    2021-01-31 05:52

    Today we have $eleMatch operator to achieve this, as discussed here - Retrieve only the queried element in an object array in MongoDB collection

    But this question poses some interesting design choices, which I am also struggling to make today. What should be the preferred choice from given two options if frequent CRUD is required in embedded documents?

    I found, it is easy to perform CRUD with new $set/$unset operators, on embedded documents, when ID s used as property names. And if client can get hold of ID to make edits, it is better than array, IMO. Here is another useful blogpost by Mongodb about schema design and making these design decisions

    http://blog.mongodb.org/post/87200945828/6-rules-of-thumb-for-mongodb-schema-design-part-1

提交回复
热议问题