MongoPostexecuter

Group

Postexecution

Function

This postexecuter executes an upsert or delete on a MongoDB document.

Configuration file

sample_mongo_postexecuter.properties

Description


This postexecuter can insert a document into a MongoDB (upsert operation) or delete one from it.

To do this, create the basic data in the target structure of the profile and then run the JsonCreationUnit in phase 5 to create a JSON document.

After that, the MongoPostexecutor has to be executed, which manages communication with the MongoDB and generates a BSON document from the JSON document. A MongoDB stores datasets as BSON documents. BSON is a binary representation of JSON documents but contains more data types than JSON. To create these types of data, MongoDB offers certain methods that you can specify instead of specific values in a document to be inserted. See parameter Cast and the example below.

Description of Parameters


Parameter

Description

MongoDB-Alias

The alias of the connected MongoDB database.

Operation

The operation to be executed. Allowed values: Upsert, Delete.

Collection

The collection in which to insert the document. Note: A collection is a grouping of MongoDB documents and is roughly equivalent to a table in an SQL database.

Cast

Since the JsonCreationUnit can only generate 'normal' JSON, it is not directly possible to create the syntactically correct method calls that can be used in the MongoDB. To make this possible, you can specify the names of the methods that the postexecuter recognises in the JSON document generated by the JsonCreationUnit and then generates a syntactically correct MongoDB call. See example below.

Example


Assume the following target structure.


images/download/attachments/55939025/140-version-1-modificationdate-1646025505535-api-v2.png


We enter the fixed value ObjectId() in field _id, the fixed value Peter Hall in field Name and in field DateOfBirth we use the following function chain.


now()
 
create W3CDTF from date (a) for Target Timezone (b)
a Ergebnis: 1
b Wert: UTC
concat(a,b,c,d,e,f,g,h, [CR-support i])
a Wert: ISODate(
b Ergebnis: 2
c Wert: )
d Wert:
e Wert:
f Wert:
g Wert:
h Wert:
i Wert:


In Phase 5 we use the JsonCreationUnit with value MyData for parameter Start at node to create the temporary JSON document.

Afterwards, also in phase 5, we execute the MongoPostexecutor with the following properties configuration file.


sample_mongo_postexecuter.properties
MongoDB-Alias=_data
Operation=Upsert
Collection=demo
Cast=ISODate,ObjectId


Here is the original document created by JsonCreationUnit.

{"_id":"ObjectId()","Name","Peter Hall", "DateOfBirth":"ISODate(2019-01-30T07:59:05Z)"}

Following is the document actually inserted by the postexecuter.

{"_id":ObjectId("5c52a06c0bafb86b5e46ffec"),"Name","Peter Hall", "DateOfBirth":ISODate("2019-01-30T07:59:05Z")}


So you create a method call as a normal string in a field of the target structure. The JsonCreationUnit will then set the double quotes around it and the postexecuter will remove them and put them around the argument value of the method instead.

See Also