Trying to create collection name without last name s but default in s is added with collection name in mongodb.So how to avoid s with collection name.
data.controller.model.js:
var NewModel = require(path.resolve('./models/data.model.js'))(collectionname);
NewModel.create({}, function(err, doc) { });
data.model.js:
/* model.js */
'use strict';
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
function dynamicModel(suffix) {
var collsName = suffix.toLowerCase();
var newSchema = new Schema({
product_name: {
type: String
}
}, { collection: collsName });
return mongoose.model(suffix, newSchema);
}
module.exports = dynamicModel;