How to stop Mongoose from adding an s at the end of a collection name?

Sometimes, we want to stop Mongoose from adding an s at the end of a collection name.

In this article, we’ll look at how to stop Mongoose from adding an s at the end of a collection name.

How to stop Mongoose from adding an s at the end of a collection name?

To stop Mongoose from adding an s at the end of a collection name, we can set the collection property when we create the schema.

For instance, we write

const dataSchema = new Schema({
  //..
}, {
  collection: 'data'
})

to create a Schema instance with an object that sets the collection property.

The collection property is set to the name we want for the collection.

Conclusion

To stop Mongoose from adding an s at the end of a collection name, we can set the collection property when we create the schema.