@exocet/pandora-mongodb
v0.0.1-alpha.0
Published
Pandora MongoDB persistence addon
Downloads
5
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:
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
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.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:
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:
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:
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:
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:
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