Mongoose subdocuments vs nested schema

后端 未结 6 939
萌比男神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:12

    There are some difference between the two:

    • Using nested schema is helpful for validation.

    • Nested schema can be reused in other schemas.

    • Nested schema add '_id' field to the subdocument unless you used "_id:false"

提交回复
热议问题