Stop Mongoose from creating _id property for sub-document array items
Asked 07 September, 2021
Viewed 2.5K times
  • 49
Votes

If you have subdocument arrays, Mongoose automatically creates ids for each one. Example:

{
    _id: "mainId"
    subDocArray: [
      {
        _id: "unwantedId",
        field: "value"
      },
      {
        _id: "unwantedId",
        field: "value"
      }
    ]
}

Is there a way to tell Mongoose to not create ids for objects within an array?

6 Answer