Automation Action – Update MongoDB | ThinkAutomation

Automation Action: Update MongoDB

Create or update MongoDB documents.

Insert, Update or Delete documents in a MongoDB collection. This action can update any local MongoDB, or cloud based MongoDB compatible document databases including Amazon DocumentDB, Azure Cosmos and MongoDB Atlas.

Specify the MongoDB Connection String, Database Name & Collection Name.

Select the Operation:

  • Insert: To insert a new document.
  • Upsert: If you want an existing document returned from the Query to be updated. If no document is returned from the Query then a new document will be inserted.
  • Update: To Update one or more existing documents.
  • Delete: To delete one or more existing documents.

If Upsert, Update or Delete is selected you must specify the Query Json. See: Query Documents — MongoDB Manual for query syntax. You can use %variable% replacements in the query and document json. If the value is a string then it must be enclosed in quotes. For example:

 { status: "%statuscode%" }

Click the Test Query button to test the connection and query. A maximum of 100 documents will be returned when using the Test option.

Enter Document Json for Insert, Upsert or Update.

If Update or Delete is selected then you can enable All Matching Documents. If enabled then all documents returned from the query will be updated/deleted.

Example Update:

With Query set to:

 { "Name" : { "$gt" : "A" } }

And Document Json set to:

 { "$set" : { "Downloads" : 11 } }

If All Matching Documents is enabled this would set the ‘Downloads’ field to 11 for all documents with ‘Name’ field greater than ‘A’. If All Matching Documents not enabled then the first document found would be updated.

If you want to store a full copy of the incoming message you can use the built-in variable %Msg_Json%. If the incoming message body is already Json (for example, if using the Database message source) then you can set the Document Json to %Msg_Body%.

You can use the Create Json action to create a Json document to insert/update.

You can assign the result of the operation to a variable. Select from the Assign Result To list. For Update/Delete operations the result will be the number of documents affected. For Insert/Upsert operations the result will be the _id of the Inserted/Updated document.

This is one action from over 180 actions included with ThinkAutomation. The ThinkAutomation business process automation (BPA) solution is designed to automate on-premises and cloud-based business processes that are triggered from incoming messages. Automate messages received by email, database updates, webhooks, web forms, web chat, SMS messages, Twitter, Teams messages, documents, local files and other messages sources. Create any number of workflow automations using the drag-and-drop low-code designer. Simple fixed pricing, with unlimited message processing reduces overall costs compared to hosted automation solutions.

You can also extend ThinkAutomation by creating your own custom automation actions using the built-in designer and C#/VB.net code editor.

Download Free 30 Day Trial

Back To Automation Actions List

ThinkAutomation Home