0

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;
Pappa S
  • 303
  • 1
  • 8
  • 21
  • Does this answer you question https://mongoosejs.com/docs/guide.html#collection – vishnu May 28 '20 at 16:06
  • also this https://stackoverflow.com/questions/22391706/is-there-a-way-to-prevent-mongodb-adding-plural-form-to-collection-names/24464105 – Jeffrey Ram May 28 '20 at 18:04

0 Answers0