1.1.4 • Published 4 years ago
mongodbconnection-wrapper v1.1.4
model def
var BaseModel = require('mongodbconnection-wrapper').getBaseModel();
class VotingModel extends BaseModel {
constructor(dbMgr, options){
super(dbMgr, options);
this.idName = "v"
this.modelName = 'votings';
}
}
module.exports = VotingModel;
schema def
'use strict';
function loadSchema(Schema,db){
var voting = {
"_id":{
type:String,
trim:true
},
"userId" :{
"type": String,
"required": true
},
"cOn" : {
type : Date,
default: Date.now
},
"mOn" : {
type : Date,
default: Date.now
}
};
db.model('votings', new Schema(voting), 'votings');
}
module.exports = loadSchema;
initializing
var dbMgr = require('mongodbconnection-wrapper');
function initiateDataBase(callback) {
var dbname = process.env.NODE_ENV === 'test' ? "test" : undefined;
debug("initiating database");
var modelsInst = dbMgr.getModel();
return dbMgr.initialize(config.get("db"),{dbName: dbname, modelPath: "./db/models", schemaPath:"./db/schemas"})
.then(function(dbMgr){
return callback && callback(dbMgr);
});
}
initiateDataBase();