0.0.21 • Published 5 years ago

mongoorm v0.0.21

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

CircleCI codecov License: MIT NPM Download NPM

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:

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,
});
0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago

1.0.0

6 years ago