MongoPostexecuter

Configuration file

sample_mongo_postexecuter.properties

Class name

com.ebd.hub.datawizard.postexec.MongoPostexecutor

Description


This postexecuter performs an operation on a MongoDB document.

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.

Parameters


Parameter

Description

MongoDB-Alias

The alias of the connected MongoDB database.

Collection

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

Operation

The operation to be executed.

Upsert - Inserts a new document if not already present. Otherwise, the existing document is completely replaced.

Replace - Replaces the existing document. If it does not exist, no change is made.

Update - Only the specified/included fields of the document are replaced.

Insert - Insert a new document.

Delete - Delete document.

UpdateMany - Update of several documents.

DeleteMany - Delete of several documents.

Filter

The filter used to define the documents to which the changes are to be applied, e.g. for UpdateMany and DeleteMany. Example: {“status”: “old”}

If you want to refer to all documents, use {}.

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/177912793/140-version-1-modificationdate-1726807744226-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=mongodb
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.