MongoPostexecuter
Group |
|
Class Name |
com.ebd.hub.datawizard.postexec.MongoPostexecutor |
Function |
This postexecuter executes an upsert or delete on a MongoDB document. |
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 destination 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 destination structure.
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.
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.
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 destination 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.