mydb connect middleware
Connect middleware to expose documents through MyDB.
// dependencies
var mydb = require('mydb-expose');
var express = require('express');
var app = express();
var db = require('monk')():
// middleware
app.use(express.cookieParser());
app.use(mydb({ mongo: '127.0.0.1:27017', url: '127.0.0.1:3000' }));
// example session route
app.post('/login', function(req, res){
req.session.set('user_id', '123');
res.send(200);
});
// example document expose
app.get('/some/doc', function(req, res){
res.send(db.get('collection').findOne({ some: 'query' }));
});
Options:
url
cloudup.mydb.io
or a reference to the mydb
redis
localhost:6379
mongo
monk
instancelocalhost:27017/test
sessionExpose
'-sid'
)The express method is overridden to detect monk
-style Promise
objects.
If the request contains the header X-Requested-With: MyDB
.
Points to the
Operations executed on the session
object defer the response sent to
the client automatically, unless a callback is passed to one of the
functions below.
Errors are next
d automatically.
The object is populated with the latest snapshot from the database.
Reloads the session from database.
Calls $set
with the given key
and val
.
Calls $unset
with the given key
.
Calls $pop
with the given key
.
Calls $pop
with the given key
and -1
, producing a shift.
Calls $push
to the given key
with val
.
Calls $push
to the given key
with vals
.
Calls $pull
with the given key
and val
.
Calls $pullAll
with the given key
and vals
.
Calls $rename
with the given key
and newKey
.
Gets the given key
asynchronously. Normally you just want to access
req.session[key]
.