Mongoose subdocuments vs nested schema

后端 未结 6 998
萌比男神i
萌比男神i 2020-11-29 17:59

I\'m curious as to the pros and cons of using subdocuments vs a deeper layer in my main schema:

var subDoc = new Schema({
  name: String
});

var mainDoc = n         


        
6条回答
  •  北海茫月
    2020-11-29 18:35

    According to the docs, it's exactly the same. However, using a Schema would add an _id field as well (as long as you don't have that disabled), and presumably uses some more resources for tracking subdocs.

    Alternate declaration syntax

    New in v3 If you don't need access to the sub-document schema instance, you may also declare sub-docs by simply passing an object literal [...]

提交回复
热议问题