Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 350
adsurbum Avatar asked Jul 29 '13 21:07

adsurbum


1 Answers

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.

like image 82
Andreas Hultgren Avatar answered Sep 28 '22 11:09

Andreas Hultgren