express4-mongo
v1.0.2
Published
``` npm install express4-mongo ```
Downloads
6
Readme
express4-mongo
Install
npm install express4-mongo
use
const express = require('express');
const database = require('express4-mongo')
var app = express();
app.use(database({
database: "lemon", //dbname
host:"" // Your mongodb Host
}))
find
in express route
router.get('/', function(req, res, next) {
const db = req.db // db object
db
.collection('news')
.find({},function(err, result){
//result in here
})
})
limit or skip or sort
router.get('/', function(req, res, next) {
const db = req.db // db object
db
.collection('news')
.find({},{
limit:5,
skip:5,
sort:{_id:-1} // reverse 1 normal
},function(err, result){
//result in here
})
})
update
db.collection('users').update(
{username:username}, //query
{remove:false}, // update data
function(err,result){
// result
})
remove
db.collection('users').remove(
{username:username}, //query
function(err,result){
//result
})
insert
db.collection('users').insert({
username:username,
email:email,
phone:phone,
password:password
},function(err,result){
// result
})