Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/benoitclaveau/damless-mongo
Mongo service for dambreaker
https://github.com/benoitclaveau/damless-mongo
Last synced: about 1 month ago
JSON representation
Mongo service for dambreaker
- Host: GitHub
- URL: https://github.com/benoitclaveau/damless-mongo
- Owner: BenoitClaveau
- License: mit
- Created: 2018-04-12T07:51:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-02T14:05:35.000Z (almost 4 years ago)
- Last Synced: 2024-04-29T09:21:59.582Z (8 months ago)
- Language: JavaScript
- Size: 210 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# damless-mongo
[Mongo](https://www.npmjs.com/package/mongodb) service for [damless](https://www.npmjs.com/package/damless).[![NPM][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Coverage Status][coveralls-image]][coveralls-url]## Features
* [damless](https://www.npmjs.com/package/damless)
* [Mongo API](http://mongodb.github.io/node-mongodb-native/3.1/api/)## REST api
Method | Param | DamLess method
--- | --- | ---
GET | /:id | httpFindOne
GET | /? | httpFind
POST | | httpInsertOne
PUT | /:id | httpSaveOne
PATCH | /:id | httpUpdateOne with $set
DELETE | /:id | httpDeleteOne## Create an api
```js
const { Http } = require("damless-mongo");
class Api extends Http {//giveme is the dependency injection service used by damless
constructor(giveme) {
super(giveme, "");
};...
}
```## Http methods
Method | Description
--- | ---
httpFindOne |
httpFind |
httpInsertOne |
httpInsertMany |
httpSaveOne |
httpUpdateOne |
httpSaveMany |
httpUpdateMany |
httpDeleteOne |
httpDeleteMany |
httpCount |
httpAggregate |## Stream methods
Method | Description
--- | ---
saveOne |
save |
insertOne |
insert |
updateOne |
update |
replaceOne |
deleteOne |
delete |
findOne |
find |
aggregate |
count |## Mongo api methods
Method | Description
--- | ---
mongoInsertOne |
mongoInsertMany |
mongoAggregate |
mongoBulkWrite |
mongoCreateIndex |
mongoCreateIndexes |
mongoCount |
mongoCreateIndexes |
mongoDeleteOne |
mongoDeleteMany |
mongoDistinct |
mongoDrop |
mongoDropIfExists |
mongoDropIndex |
mongoDropIndexes |
mongoFindOne |
mongoFind |
mongoFindOneAndDelete |
mongoFindOneAndReplace |
mongoFindOneAndUpdate |
mongoGeoHaystackSearch |
mongoGeoNear |
mongoGroup |
mongoMapReduce |
mongoReplaceOne |
mongoSave |
mongoUpdateOne |
mongoUpdateMany |## Cutomize your api
```js
const { Http } = require("damless-mongo");
const { promisify } = require("util");
const stream = require("stream");
const pipeline = promisify(stream.pipeline);class Api extends Http {
// giveme is the dependency injection service used by damless
constructor(giveme) {
super(giveme, "");
};// override the default httpFind an use Crud primitives
async httpFind(context, stream, headers) {
// get a mongo cursor
const cursor = this.findWords(context.query.q);
await pipeline(
cursor,
stream
);
}
}
```## Add the mongo connection string in damless.json
```damless.json
{
"mongo": {
"connectionString": "mongodb://localhost:27017/database"
},
}
```## Inject damless-mongo service
```services.json
{
"services": [
{ "name": "mongo", "location": "damless-mongo" }
]
}
```Or in javascript
```js
const DamLess = require("damless");
const damless = new DamLess();
damless.inject("mongo", "damless-mongo");
```## Installation
```bash
$ npm install damless-mongo
```## Test
To run our tests, clone the damless-mongo repo and install the dependencies.
```bash
$ git clone https://github.com/BenoitClaveau/damless-mongo --depth 1
$ cd damless-mongo
$ npm install
$ mongod --dbpath ./data/db
$ node.exe "../node_modules/mocha/bin/mocha" tests
```[npm-image]: https://img.shields.io/npm/v/damless-mongo.svg
[npm-url]: https://npmjs.org/package/damless-mongo
[travis-image]: https://travis-ci.org/BenoitClaveau/damless-mongo.svg?branch=master
[travis-url]: https://travis-ci.org/BenoitClaveau/damless-mongo
[coveralls-image]: https://coveralls.io/repos/BenoitClaveau/damless-mongo/badge.svg?branch=master&service=github
[coveralls-url]: https://coveralls.io/github/BenoitClaveau/damless-mongo?branch=master