# @exocet/pandora-mongodb

> Pandora MongoDB persistence addon

Latest version **0.0.1-alpha.0** (published 2019-04-23) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @exocet/pandora-mongodb
pnpm add @exocet/pandora-mongodb
yarn add @exocet/pandora-mongodb
bun add @exocet/pandora-mongodb
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1-alpha.0 |
| Published | 2019-04-23 |
| First published | 2019-04-23 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 48.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Exocet |
| Maintainers | codermarcos, vflopes |
| Keywords | pandora, mongodb, mongo, persistence, addon |

## Links

- npm: https://www.npmjs.com/package/@exocet/pandora-mongodb
- Repository: https://github.com/exocet-engineering/pandora-mongodb
- Homepage: https://github.com/exocet-engineering/pandora-mongodb#readme
- Issues: https://github.com/exocet-engineering/pandora-mongodb/issues
- npm.io page: https://npm.io/package/@exocet/pandora-mongodb

## Dependencies (3)

- [qs](https://npm.io/package/qs.md) ^6.7.0
- [mongodb](https://npm.io/package/mongodb.md) ^3.2.3
- [jsonpath](https://npm.io/package/jsonpath.md) ^1.0.1

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 0.0.1-alpha.0 (latest) — 2019-04-23

## README

# Pandora MongoDB

Addon to provide flow and setup functions to MongoDB persistence for Pandora.

```
npm install --save @exocet/pandora-mongodb
```

---------------------------

## Setup

Available features:

* Create text indexes
* Provides AQS query parser
* Flow steps: insert (index), update, delete, exists and search

To add this addon into your project, put the addon spec into your endpoint YAML:

```yaml
kind: Pandora/endpoint
metadata:
  name: myEndpoint
spec:
  addons:
    - name: mongodb
      package: "@exocet/pandora-mongodb"
      flow: true
      setup: true
  configuration:
    mongodb: # Any configuration here will be passed to client configuration (1)
      database: myDatabase
      url: mongodb://localhost:27017
      collections:
        - entityName: myNamespace.myEntity # To create index and mapping for an entity, pass the entity name, the settings bellow are the defaults
          textIndex: true
        - collectionName: myCollection
          textIndex: true
```

1. [Client configuration](http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html)

After the setup the following property of the context will be available:

* `.application.dbs.mongoClient` - The client connected to MongoDB
* `.application.dbs.mongodb` - The connected database reference

---------------------------

## Hooks

The hooks created by this addon are:

* **mongodbQueryParsers** (`.service.hooks.useHook('mongodbQueryParsers')`) - Synchronous hook that parses the search AQS query into MongoDB aggregation pipeline.
	```javascript
	const [queryParsers] = this.service.hooks.useHook('mongodbQueryParsers');
	const queryParser = queryParsers(entityName);
	const {
		pipeline, // The aggregation pipeline
		hasMatch // Boolean to indicate if the pipeline have the match operation
	} = queryParser(
		aqsQuery,
		{ // Optional options
			pipeline: [], // Existent aggregation pipeline
		}
	);
	```

---------------------------

## Flow

The provided flow type and steps are listed bellow:

* **insert** - This flow step insert data into MongoDB:
	```yaml
	kind: Pandora/flowStep
	metadata:
	  name: entityPersistence
	  labels:
	    operation: insert
	spec:
	  type: mongodb # Flow step type
	  options:
	    operation: insert # Defines that is an insert operation
	    inboundFrom: request.data # The path to the data to be inserted (acquired from execution context)
	    idFrom: null # If you want to use a custom ID instead of UUIDv4 you can pass the path from the execution context to get the ID value
	    collectionName: null # If you're using custom collection name, pass the name here
	    entity: # The entity to define the input parser hook
	      namespace: myNamespace
	      name: myEntity
	```
* **exists** - This flow step check if an entity exists by ID:
	```yaml
	kind: Pandora/flowStep
	metadata:
	  name: entityPersistence
	  labels:
	    operation: exists
	spec:
	  type: mongodb
	  options:
	    operation: exists
	    idFrom: request.data.id # The path of the ID
	    outboundTo: null # The execution path of the context to put the found ID, is an useful flow step to put before update and delete flows to get the native ID before operating the entity
	    collectionName: null
	    entity:
	      namespace: myNamespace
	      name: myEntity
	```
* **update** - This flow step updates entities:
	```yaml
	kind: Pandora/flowStep
	metadata:
	  name: entityPersistence
	  labels:
	    operation: update
	spec:
	  type: mongodb
	  options:
	    operation: update
	    inboundFrom: request.data
	    idFrom: request.data.id # The path of the ID to update entity
	    collectionName: null
	    entity:
	      namespace: myNamespace
	      name: myEntity
	```
* **delete** - This flow step deletes entities:
	```yaml
	kind: Pandora/flowStep
	metadata:
	  name: entityPersistence
	  labels:
	    operation: delete
	spec:
	  type: mongodb
	  options:
	    operation: delete
	    idFrom: request.data.id
	    collectionName: null
	    entity:
	      namespace: myNamespace
	      name: myEntity
	```
* **search** - This flow step searches for entities using AQS:
	```yaml
	kind: Pandora/flowStep
	metadata:
	  name: entityPersistence
	  labels:
	    operation: search
	spec:
	  type: mongodb
	  options:
	    operation: search
        queryFrom: request.query # The execution context path that have the AQS querystring
        outboundTo: response # The execution context path to put the search result
        pipelineFrom: null # The execution context path that have an existing pipeline instance to append the parsed AQS filters, pass null to indicate the flow step to generate a new instance
        collectionName: null
	    entity:
	      namespace: myNamespace
	      name: myEntity
	```

---
_Source: https://npm.io/package/@exocet/pandora-mongodb · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
