Mongoose: doesn't put _id in inline document

var Embedded = new Schema({ some: String }) var Main = new Schema({ other: String, em: [Embedded] }) 

On Main.save ({other: 1, em: [{some: 2}]}) mongoose adds an object {other: 1, em: [{some: 2, "_ id": ObjectId ("51f6d89a6269170000000039")}] } to the database.

Can I tell mongoose not to add _id to the inline document?

+6
source share
1 answer

When defining a schema, you can specify parameters as the second parameter. Set _id to false to disable auto _id.

 var Embedded = new Schema({ some: String }, { _id: false }) 

See documents .

+16
source

Source: https://habr.com/ru/post/950581/


All Articles