8
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?

adsurbum
  • 3,107
  • 3
  • 22
  • 27

1 Answers1

18

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.

Andreas Hultgren
  • 14,763
  • 4
  • 44
  • 48