MongoDB Actions¶
Actions are the operations (or API operations) that will take place as a result of the trigger defined in the upstream application. These actions you can perform on MongoDB by simple drag-drop and data mapping of elements and values from the trigger, derived values using formulas or desired constant that you may wish to map.
All of the actions that you see below automate what you can do manually on MongoDB database.
As shown below, you can Create Collection and Add Document, Create Document, Delete or Update the document based in response to a trigger event.
Create Collection And Add Document¶
To create a collection in the MongoDB database and add the document in it you can use this action. If the collection is already present then this action will only add the document in it.
You can map fields data using trigger data or you can use Excel-style functions.
For example in below Figure 2, key values of document data are build using the attributes from ServiceNow (Privileged) and time_of_incident
key set to the value using the Excel function.
Create Document¶
This action can be used to create a document inside a selected collection.
Following fields are required to perform the action:
1. Collection name - List of collection will be populated into the form from which you can select collection where you want to add document.
2. Document Data - Add document data in JSON format.
You can map fields data using trigger data or you can use the Excel-style functions.
For example in below Figure 3, we have selected testcollection
collection from the database. In order to add document data to this collection we have mapped key data to the ServiceNow trigger fields like Category
and Description
.
Delete The Document¶
This action can be used to delete the document inside the selected collection based on defined criteria. You can delete all the documents or you can delete a single document which satisfy the chosen criteria.
Following fields are required to perform the action:
1. Choose Collection - List of the collections in which you want to add document.
2. Add where conditions - Add criteria to delete the document into JSON format.
3. Delete All Matched Document - This fields is by default flagged as false. If you want to delete all the documents from the collection you need to enable this field.
For example in below Figure 4, From the testcollection
collection all the documents will get deleted if the incidentState
matches the incident State
of ServiceNow. You can map fields data using trigger data or you can use Excel-style functions.
Update The Document¶
Updates one or more collection documents in response to defined event trigger. If the defined conditions are not met then you can also perform the Upsert action. In case of the Upsert action if the trigger finds an existing document it will update it, if not it will create a new document.
You can select the updates that you want to perform on the selected documents. You can use data Mapping and Transformation and excel functions.
Following fields are required to perform the action:
1. Collection - List of the collections in which you want to add document.
2. Set - Add the JSON structure here which is key value pair where key will be the attributes which you want to update to the value.
3. Add where condition - Add criteria to update the document into JSON format.
4. Update all matched document - This flag will update all the documents which match the where criteria. By default this flag is disabled, please enable if it is important for the action in MongoDB.
5. Upsert the document - This flag is by default false. If this flag is set to true then it will create the document with the set value if their are no matching documents found.
In the example shown in Figure 5, whenever an Incident is updated on ServiceNow (Privileged), a document is updated in MongoDB collection. The document keys closedBy
, openedBy
and incident_name
are mapped to the ServiceNow attributes. You can add where condition
like in the example shown here documents are updated which matches the incident_name
. All documents which match the defined conditions will be updated with the new values, and new documents will be created in the database if they do not exist.