rx-mongodb
v1.0.0
Published
rx-mongodb is a reactive drive to mongodb for rxjs developers
Downloads
9
Maintainers
Readme
rx-mongodb is a reactive drive to mongodb for rxjs developers
Installation
npm install rx-mongodb
#run tests
npm install rx-mongodb
goto: $/node_modules/rx-mongodb
npm test
Connecting to MongoDB
const mongodb = require('mongodb');
const rxMongodb = new RxMongodb(mongodb);
const dbName = 'example';
const collectionName = 'users';
const connectionString = 'mongodb://localhost:27017/'+dbName;
rxMongodb
.connect(connectionString)
.subscribe(
db=>{
//Your code from here
}
);
Closing database connection
const mongodb = require('mongodb');
const rxMongodb = new RxMongodb(mongodb);
const dbName = 'example';
const collectionName = 'users';
const connectionString = 'mongodb://localhost:27017/'+dbName;
rxMongodb
.connect(connectionString)
.flatMap(db=>rxMongodb.close())
.subscribe(
retult=>{
//Your code from here
}
);
Inserting a Document
const mongodb = require('mongodb');
const rxMongodb = new RxMongodb(mongodb);
const dbName = 'example';
const collectionName = 'users';
const connectionString = 'mongodb://localhost:27017/'+dbName;
rxMongodb
.connect(connectionString)
.flatMap(db=>rxMongodb.insert(collectionName, toInsert))
.subscribe(
insertResult=>{
//Your code from here
}
);
Updating a document
const mongodb = require('mongodb');
const rxMongodb = new RxMongodb(mongodb);
const dbName = 'example';
const collectionName = 'users';
const connectionString = 'mongodb://localhost:27017/'+dbName;
rxMongodb
.connect(connectionString)
.flatMap(db=>rxMongodb.update(collectionName, {id: 111}, {$set: {id: 999}}))
.subscribe(
updateFindResult=>{
//Your code from here
}
);
Delete a document
const mongodb = require('mongodb');
const rxMongodb = new RxMongodb(mongodb);
const dbName = 'example';
const collectionName = 'users';
const connectionString = 'mongodb://localhost:27017/'+dbName;
rxMongodb
.connect(connectionString)
.flatMap(db=>rxMongodb.remove(collectionName, {id: 111}))
.subscribe(
removeResult=>{
//Your code from here
}
);