1.0.4 • Published 3 years ago

damless-mongo v1.0.4

Weekly downloads
12
License
MIT
Repository
github
Last release
3 years ago

damless-mongo

Mongo service for damless.

NPM Build Status Coverage Status

Features

REST api

MethodParamDamLess method
GET/:idhttpFindOne
GET/?httpFind
POSThttpInsertOne
PUT/:idhttpSaveOne
PATCH/:idhttpUpdateOne with $set
DELETE/:idhttpDeleteOne

Create an api

const { Http } = require("damless-mongo");
class Api extends Http {

    //giveme is the dependency injection service used by damless
    constructor(giveme) {
        super(giveme, "<collectionName>");
    };

    ...
}

Http methods

MethodDescription
httpFindOne
httpFind
httpInsertOne
httpInsertMany
httpSaveOne
httpUpdateOne
httpSaveMany
httpUpdateMany
httpDeleteOne
httpDeleteMany
httpCount
httpAggregate

Stream methods

MethodDescription
saveOne
save
insertOne
insert
updateOne
update
replaceOne
deleteOne
delete
findOne
find
aggregate
count

Mongo api methods

MethodDescription
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

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, "<collectionName>");
    };

    // 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

{
	"mongo": {
        "connectionString": "mongodb://localhost:27017/database"
    },
}

Inject damless-mongo service

{
  "services": [
    { "name": "mongo", "location": "damless-mongo" }
  ]
}

Or in javascript

const DamLess = require("damless");
const damless = new DamLess();
damless.inject("mongo", "damless-mongo");

Installation

$ npm install damless-mongo

Test

To run our tests, clone the damless-mongo repo and install the dependencies.

$ 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
1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.3

4 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.30

5 years ago

0.0.29

6 years ago

0.0.28

6 years ago

0.0.27

6 years ago

0.0.26

6 years ago

0.0.25

6 years ago

0.0.24

6 years ago

0.0.23

6 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago