0.0.10 • Published 4 years ago

cc-mongo v0.0.10

Weekly downloads
4
License
ISC
Repository
bitbucket
Last release
4 years ago

cc-mongo

Instaling

npm install --save cc-mongo

How To use

const Mongoose = require('mongoose').Mongoose;
const ModelHandler = require('cc-mongo');
const db = new Mongoose();
db.connect('http://localhost:27017/meteor', { useNewUrlParser: true, useFindAndModify: false }).catch(console.error);

// In our Model Definition
const collectionName = 'user';
const userSchema = new db.Schema({
  _id: { type: String, required: true },
  name: { type: String },
  status: { type: Boolean },
  isRemove: { type: Boolean, default: false },
  createdAt: { type: Date, default: Date.now },
  updatedAt: { type: Date, default: Date.now }
}, {
  collection: collectionName
});

//here we use mongo handler
const User = ModelHandler(db, collectionName, userSchema);

module.exports = User;

Available Methods

MethodsParamsReturn
insertmodel, sessionmodel
updateprops, sessionmodel
remove/hideprops, sessionmodel
delete_id, sessionmodel
insert(model, session):
  • model: the new model to insert into the collection.
  • session | optional: tbd.
update(props, session)
  • props | object:
    • model: the object with new changes.
    • selector | optional: thq condition to the update query. By default: { _id: model._id }.
    • options | optional: to use as option on mongoose updateOne method.
remove(props, session) / hide(props, session) soft delete
  • props | object: this method is a direct access to update.
    • model: the object with new changes.
    • selector | optional: thq condition to the update query. By default: { _id: model._id }.
    • options | optional: to use as option on mongoose updateOne method.
  • Before update call, model is manipulated with properties below:
    • updatedAt: new Date()
    • removedAt: new Date()
    • isRemove: true
delete(_id, session) hard delete
  • _id: model id to delete
0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago