mongoorm
v0.0.21
Published
ORM for Mongodb in Node JS
Downloads
4
Readme
Installation
$ npm install mongoorm
Connecting to MongoDB and configure mongoorm
const MongoORM = require('mongoorm')
MongoORM.connect(connectionString, options).then(() => {
console.log("mongoorm is connected.");
});
For more information on the connection options:
- URI Connection String: MongoDB connection string URI.
- Connection Settings: Reference on the driver-specific connection settings.
Document Schema Creation
Schema can be created by extending Document
const { Document } = mongoorm;
class User extends Document {
initFields(fields) {
return {
firstName: fields.String(),
lastName: fields.String(),
address: {
city: fields.String(),
pin: fields.String(),
},
};
}
}
CRUD Operations
//get collection
const user = new User({ document: 'user' });
//example data
let userData = {
firstName: 'Deep',
lastName: 'Patel',
address: {
city: 'Mehsana',
pin: '384002',
},
};
//create document with above data
let document = user.create(userData);
//create document
await document.save();
//update document
document.firstName.set('hello');
await document.save();
//delete document
await document.delete();
Configure logging
You can configure your own logger using -
mongoorm.setLogger({
info: console.info,
error: console.error,
});