mongodb-util
v1.0.8
Published
A utility on top of Mongoose to achieve mongo database, models organization
Downloads
2
Maintainers
Readme
ws: a node.js websocket library
mongodb-util
is a simple way to organice your mongoose models, connections...
Installing
npm install --save mongodb-util
Setting up a connection
var mongodbUtil = require("mongodb-util");
var db = mongodbUtil({
host:"localhost",
dbName:"example",
user:"root",
password:"gar",
models:"your path directory where file models are."
}, "example-dev");
Your first model
Create a folder where put your model.js filename: person.js
var persons = function (mongodb) {
var model = this.define('persons',{
id : String,
name : String,
lastname : String,
email : String,
age : Number
});
}
module.exports = persons;
Your first query
var db = require('mongodb-util').getSchema("example-dev");
db.persons.find((err, result)=>{
console.log(arguments)
});
Syncing
var db = require('mongodb-util').getSchema("example-dev");
db.sync().then(function(){
console.log("Sync Done :D");
}).error(function(err){
console.log("Sync err:");
console.log(err);
})