updateDocument

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 Update Document

This activity allows you to update one or more documents or replace a document from a collection in MongoDb database based on a matching criteria entered as a JSON

Installation

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

Configuration

Settings:
Name Type Description
connection connection Choose a MongoDB connection from the drop down - REQUIRED
operation string The Query operation type (Update One Document or Update Many Documents or Replace One Document) - REQUIRED
databaseName string MongoDB databse to update documents - REQUIRED
collectionName string The collection within the MongoDB database to update documents - REQUIRED
timeout int32 Timeout in seconds for the activity's operations
Input:
Name Type Description
criteria object The matching criteria entered as a JSON - ***In case an empty JSON is provided and if operation is Update Many Documents,
all the documents in the collection will be updated***
updateData object The data to be updated with
Output:
Name Type Description
matchedCount int64 Returns the total documents that matched the criteria for update
updatedCount int64 Returns the total documents that were updated

Example

The below example shows the values for MongoDB Update Document activity in the Flogo app JSON as well as the connection object referenced by the activity. The MongoDB Update Document activity in this example updates all the documents in a collection that has a key called 'location' with value' Palo Alto' with the provided udpateData

{
  "id": "MongoDBUpdateDocument",
  "name": "MongoDBUpdateDocument",
  "description": "Mongodb Update Document activity",
  "activity": {
    "ref": "#updateDocument",
    "settings": {
      "connection": "conn://a7730ae0-0199-11ea-9e1b-1b6d6afda988",
      "operation": "Update Many Documents",
      "databaseName": "sample",
      "collectionName": "test",
      "timeout": 0
    },
    "input": {
      "criteria": {
        "location": "Palo Alto"
      },
      "updateData": {
        "location": "San Francisco"
      }
    }
  }
}

"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 of activity

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 {
	Criteria   interface{} `md:"criteria,required"`   // The JSON Request Object that will serve as search parameter for deciding which documents to update
	UpdateData interface{} `md:"updateData,required"` // The JSON Request Object that will serve as the update 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 {
	MatchedCount int64 `md:"matchedCount"` // A number indicating total Documents that were matched for update
	UpdatedCount int64 `md:"updatedCount"` // A number indicating total Documents that were updated by this activity

}

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(Update One Document,Update Many Documents,Replace One Document)"` // Operation to perform
	CollectionName string `md:"collectionName,required"`                                                                    // The collection within the MongoDB database to Update Documents
	Database       string `md:"databaseName,required"`                                                                      // MongoDB databse to Update Documents
	Timeout        int32  `md:"timeout"`                                                                                    // Timeout in seconds for the activity's operations
}

Settings structure

Jump to

Keyboard shortcuts

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