Mongoskin is a model tool that operates MONGODB equivalent to the database class and Mongoose is quite famous.
Mounting module
CNPM Install MongoDB
CNPM Install Mongoskin
Import Mongoskin Connect MongoDB in the test database
var mongo = require (' Mongoskin '); var true});
Operation is much the same as MongoDB native syntax just a callback
Increase
Router.post ('/doadd ',function(req, res, next) {varparam =Req.body; if(Param.username &&Param.password) { //Inserting DataDb.collection (' user '). Insert ({' username ': param.username, ' Password ':p Aram.password},function(err, result) {db.close (); if(!err) {Res.send ({' Status ': 1}); }Else{res.send ({' Status ': 0}); } }); }});
By deleting
Router.post ('/dodel ',function(req, res, next) {varparam =Req.body; if(param.id) {varObjectId =MONGO. ObjectID; Db.collection (' user '). Remove ({' _id ': ObjectId (param.id)},function(err, result) {db.close (); if(!err) {Res.send ({' Status ': 1}); }Else{res.send ({' Status ': 0}); } }); }});
Change
Router.post ('/doedit ',function(req, res, next) {varparam =Req.body; if(Param.username &&Param.password) { varObjectId =MONGO. ObjectID; //Modify A single piece of dataDb.collection (' article '). Update ({' _id ': ObjectId (param._id), ' username ':p aram.username},{$set: {' Password ': Param.password}},function(err, result) {db.close (); if(!err) {Res.send ({' Status ': 1}); }Else{res.send ({' Status ': 0}); } }); }});
Check
function (req, res, next) { db.collection (' article '). Find (). ToArray (function (err, result) { Db.close (); Res.render (' Admin/index ', {title: ' admin ', result:result} );});
Using Mongoskin to manipulate MongoDB