What are Mongoose (Nodejs) pluralization rules?

Provide the name for the collection in options while creating schema object, then Mongoose will not do pluralize your schema name.

e.g.

var schemaObj = new mongoose.Schema(
{
 fields:Schema.Type
}, { collection: 'collection_name'});

For more Info: http://mongoosejs.com/docs/guide.html#collection


The pluralization rules are in this file: https://github.com/LearnBoost/mongoose/blob/master/lib/utils.js

You can add your schema name to the 'uncountables' list, then mongoose will not pluralize your schema name.


The pluralization rules is here to ensure a specific naming convention.

The collection name should be plural, all lowercase and without spacing.

What are naming conventions for MongoDB?


I think you should ask yourself if you want to follow the main rule (ensured by mongoose as a default behavior) or get rid of it.

What are the perks ? What are the good points ?

You design first what is an user (User model) and then you store users into a collection. It totally make sense.

Your call.


If you ask yourself how to get the final name of the collection after the pluralization :

const newName = mongoose.pluralize()('User');