Why does mongoose always add an s to the end of my collection name
Why does mongoose always add an s to the end of my collection name
You can try to do it. its trying to be a smart:
var dataSchema = new Schema({..}, { collection: 'data' })
This is a API structure of mongoose.model:
Mongoose#model(name, [schema], [collection], [skipInit])
The following statement is What mongoose do is that, When no collection argument is passed, The Mongoose produces a collection name by pluralizing the model name. If you don’t like this behavior, either pass a collection name or set your schemas collection name option.
For the example:
var schema = new Schema({ name: String }, { collection: 'actor' });
Or Else
schema.set('collection', 'actor')
Or Else
var collectionName = 'actor' var M = mongoose.model('Actor', schema, collectionName);
We can add a string as a third argument to define the actual name for the collection. spanning your examples, to keep names as data and user respectively:
var Dataset = mongoose.model('data', dataSchema, 'data'); var User = mongoose.model('user', dataSchema, 'user');