qwebs-mongo
Mongo service for Qwebs server.
Features
return $mongo.db.then(db => {
});
Add the mongo connection string in config.json
{
"mongo": {
"connectionString": "mongodb://localhost:27017/database"
},
}
Declare and inject $mongo service
Via route.json
{
"services": [
{ "name": "$mongo", "location": "qwebs-mongo" }
]
}
Or in javascript
const Qwebs = require("qwebs");
const qwebs = new Qwebs();
qwebs.inject("$mongo" ,"qwebs-mongo");
Use $mongo service
Hight level api
const { CRUD } = require("qwebs-mongo");
class Api extends CRUD {
constructor($mongo) {
super("collectionName", $mongo);
};
httpStream(request, response) {
request.mongo = {
options: {
limit: parseInt(request.query.limit),
skip: parseInt(request.query.skip)
}
}
return super.httpStream(request, response);
}
Low level api
class Api {
constructor($mongo) {
this.$mongo = $mongo;
};
httpStream(request, response) {
return this.$mongo.db.then(db => {
const limit = parseInt(request.query.limit);
const skip = parseInt(request.query.skip);
const stream = db.collection("collectionName").find({}).limit(limit).skip(skip).stream();
return response.send({ request: request, stream: stream });
});
);
};
Installation
$ npm install qwebs-mongo
Test
To run our tests, clone the qwebs-mongo repo and install the dependencies.
$ git clone https://github.com/BenoitClaveau/qwebs-mongo --depth 1
$ cd qwebs-mongo
$ npm install
$ mongod --dbpath ./data/db
$ node.exe "../node_modules/mocha/bin/mocha" tests