insertDocument

package
v0.0.0-...-51b37bf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 29, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

README

MongoDB Insert Document

This activity allows you to Insert one or more documents into a collection in a MongoDb database

Installation

Flogo CLI
flogo install github.com/project-flogo/datastore-contrib/mongodb/activity/insertDocument

Configuration

Settings:
Name Type Description
connection connection Choose a MongoDB connection from the drop down - REQUIRED
operation string The Insert operation type (Insert One Document or Insert Many Documents) - REQUIRED
databaseName string MongoDB databse to Insert - REQUIRED
collectionName string The collection within the MongoDB database to Insert - REQUIRED
timeout int32 Timeout in seconds for the activity's operations
continueOnErr bool For Insert Many Documents operation, should the activity continue to insert documents when the previous insertDocument failed?
Input:
Name Type Description
data object The The data to be inserted. In case of Insert Many Documents, pass an array of JSONs
Output:
Name Type Description
insertedId string InsertedId of inserted document. In case of Insert Many Documents, a list of IDs is returned
totalCount int Applicable for Insert Many Documents only. The total numner of Documents that were attempted for Insert.
successCount int Applicable for Insert Many Documents only. The total number of successful Document Insertions.
failureCount int Applicable for Insert Many Documents only. The total number of Document insertions that failed.

Example

The below example shows the values for MongoDB Insert Document activity in the Flogo app JSON as well as the connection object referenced by the activity. The MongoDB Insert Document activity in this example attempts to insert many documents with continueOnError property set to true

{
  "id": "MongoDBInsertDocument",
  "name": "MongoDBInsertDocument",
  "description": "Mongodb Insert Document activity",
  "activity": {
    "ref": "#insertDocument",
    "settings": {
      "connection": "conn://a7730ae0-0199-11ea-9e1b-1b6d6afda988",
      "operation": "Insert Many Documents",
      "databaseName": "sample",
      "collectionName": "test",
      "timeout": 23,
      "continueOnErr": true
    },
    "input": {
      "data": [
        {
        "name": "Mongo User1",
        "age": "22",
        "location": "Palo Alto"
        },
        {
        "name": "Mongo User2",
        "age": "33",
        "location": "Seattle"
        }
      ]
    }
  }
}

"connections": {
  "a7730ae0-0199-11ea-9e1b-1b6d6afda988": {
    "id": "a7730ae0-0199-11ea-9e1b-1b6d6afda988",
    "name": "mc2",
    "ref": "github.com/project-flogo/datastore-contrib/mongodb/connection",
    "settings": {
      "name": "mc2",
      "description": "",
      "connectionURI": "<Connection URI Here>",
      "credType": "<One of None or SCRAM-SHA-1 or SCRAM-SHA-256>",
      "username": "<Enter Username here in case of SCRAM-SHA-1 or SCRAM-SHA-256>",
      "password": "",
      "ssl": false,
      "x509": false,
      "trustCert": "",
      "clientCert": "",
      "clientKey": "",
      "keyPassword": "",
      }
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

New functioncommon

Types

type Activity

type Activity struct {
	// contains filtered or unexported fields
}

Activity is a stub for your Activity implementation

func (*Activity) Cleanup

func (a *Activity) Cleanup() error

Cleanup method

func (*Activity) Eval

func (a *Activity) Eval(context activity.Context) (done bool, err error)

Eval implements activity.Activity.Eval

func (*Activity) Metadata

func (a *Activity) Metadata() *activity.Metadata

Metadata implements activity.Activity.Metadata

type Input

type Input struct {
	Data interface{} `md:"data,required"` // The JSON Object that will serve as the input data
}

Input structure

func (*Input) FromMap

func (i *Input) FromMap(values map[string]interface{}) error

FromMap method

func (*Input) ToMap

func (i *Input) ToMap() map[string]interface{}

ToMap method

type Output

type Output struct {
	InsertedID   string `md:"insertedId"`   // InsertedId of inserted document. In case of Insert Many Documents, a list of IDs is returned
	TotalCount   int    `md:"totalCount"`   // Applicable for Insert Many Documents only. The total numner of Documents that were attempted to be inserted.
	SuccessCount int    `md:"successCount"` // Applicable for Insert Many Documents only. The total number of successful Document Insertions.
	FailureCount int    `md:"failureCount"` // Applicable for Insert Many Documents only. The total number of Document insertions that failed.
}

Output structure

func (*Output) FromMap

func (o *Output) FromMap(values map[string]interface{}) error

FromMap Output

func (*Output) ToMap

func (o *Output) ToMap() map[string]interface{}

ToMap Output

type Settings

type Settings struct {
	Connection     string `md:"connection,required"`                                                   // The MongoDB connection
	Operation      string `md:"operation,required,allowed(Insert One Document,Insert Many Documents)"` // Operation to perform
	CollectionName string `md:"collectionName,required"`                                               // The collection within the MongoDB database to Insert Documents
	Database       string `md:"databaseName,required"`                                                 // MongoDB database to Insert Documents
	Timeout        int32  `md:"timeout"`                                                               // Timeout in seconds for the activity's operations
	ContinueOnErr  bool   `md:"continueOnErr"`                                                         // In case of Insert Many Documents operation, should the activity continue to insertDocument when the previous insertDocument operation failed?
}

Settings structure

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL