简体   繁体   中英

Mongoose: doesn't put _id to embedded 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 object {other:1, em:[{some:2,"_id" : ObjectId("51f6d89a6269170000000039")}]} to the database.

Can I say to mongoose not to add _id to embedded document?

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

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

See the docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM