1.1.2 • Published 2 years ago

mongo-clay v1.1.2

Weekly downloads
9
License
ISC
Repository
github
Last release
2 years ago

mongo-clay

This project is a module of functions to allow acces to a mongo db and make CRUD Actions

Install

npm install mongodb

npm install mongo-clay

How to use

var clay=require('mongo-clay');
//set DB 
clay.set('mongodb://localhost:27017/','dbName');
//set collection
var myCollection=clay.collection('collectionName');

Insert Document

var myDocument=new myCollection();

myDocument.setData({name:'Jhon'});
myDocument.setData({age:17});
myDocument.setData({email:'example@example.com'});

myDocument.save((result)=>{
	console.log(result)
});

//or

let data = {
	name:'Jhon',
	age:17,
	email:'example@example.com'
}
var myDocument=new myCollection(data);
myDocument.save((result)=>{
	console.log(result)
})

Find Documents

myCollection.find({age:17},{},(docs)=>{
	console.log(docs);
});
//or
clay.find('collectionName',{age:17},{},(docs)=>{
	console.log(docs);
});

Projections

let projection = {name:1};
myCollection.find({age:17},projection,(docs)=>{
	console.log(docs);
});
//or
clay.find('collectionName',{age:17},projection,(docs)=>{
	console.log(docs);
});

Aggregation

let rules=[
	{ '$match': {
		'age': { '$gte': 20, '$lte': 30 }
	}},
	{ '$group': {
		'_id': '$email'
	}}];
myCollection.aggregate(rules,(docs)=>{
	console.log(docs);
});
//or
clay.aggregate('collectionName',rules,(docs)=>{
	console.log(docs);
});

Update Documents

//update first document with email example@example.com
myCollection.update({email:'example@example.com'},{age:18},(result)=>{
	console.log(result);
});
//or
clay.update('collectionName',{email:'example@example.com'},{age:18},(result)=>{
	console.log(result);
});

Remove Documents

myCollection.remove({email:'example@example.com'},(result)=>{
	console.log(result);
});
//or
clay.remove('collectionName',{email:'example@example.com'},(result)=>{
	console.log(result);
});
1.1.1

2 years ago

1.0.6

2 years ago

1.1.2

2 years ago

1.1.0

4 years ago

1.0.5

4 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago