Mongoose ODM saves wrong model name in MongoDB collection Mongoose ODM saves wrong model name in MongoDB collection mongoose mongoose

Mongoose ODM saves wrong model name in MongoDB collection


Seems like they set a rule on words ending with "fe" because they normally convert to plural as "ves" (knife -> knives).

You can set your own collection name by adding another argument to Schema:

const safeSchema = new Schema({ name: String }, { collection: 'safes' })


Mongooses util.toCollectionName generates a name of the collection based on the Schema name. It does use some regexes, one of them being:

  [/(?:([^f])fe|([lr])f)$/gi, '$1$2ves'],

Which maches safe and replaces it with saves.

source