Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents
excludeRelated

Dynamic Data Manager node lets you manage the data that you want to store.

...

...

Table of Contents
excludeRelated

Model

You can choose the schema from this drop-down.

...

  • limit” specifies the number of data items to be shown per page in the result object. The maximum value is 999. Always specify a limit. If you do not specify a limit and there are more than 999 results, it will return an invalid number of results.

  • page” is the page number to be shown in the results object. The first page starts at 1.

  • sortBy” is used to sort the fetched data based on the criteria.
    For example, {"sortBy":{"modifiedAtcreatedAt":-1}} will sort the data items shown in the result array based on the modified created date displaying the latest modified created data item first.

The following image shows the result payload.

...

Item Name is asked while creating the Data item manually. Multiple data items can have the same item name. You can query the data using the item name.

...

Example

...

1

The below example will return all the values that have the status as Inactive, age greater than 32, and whose page number equals the dynamic value passed to the data manager.

If there are more than 999 items we need to concatenate the results.

Because we are doing a loop to get all the pages of data, it is a good idea while testing to add a delay to throttle the number of queries donequery requests, in case you make a mistake and created an infinite loop. Then either change changes the delay to 1 ms , or remove the delay completely.

...

Ignore the red X in this example, the validation is confused by the mustache tag, it is ultimately a number

...

The Dynamic Data Manager node is set to Read. The AND condition is set for status and age.

The number of documents per page is 999 items. Which is the max limit.

...

In sortBy, we used createdAt. You can also use modifiedAt.

The createdAt, modifiedAt, and _id are always returned in the collection.

Code Block
{ 
"$and": [{ 
        "status": "Inactive" 
    }, 
    { 
        "age":{ "$gte":"32" } 
    }],
"createdAt": { "$gt" : "{{msg.startDate}}" },
 
"limit": 999,

 "page": "{{msg.pagePntr}}",
 
"sortBy": {"createdAt":-1}
} 

...

In the init function node, set up the pagePntr to start at 1. A common mistake is to start at 0.
Also setting up the array to store the results, in this case, msg.userDataArray = [ ]

...

Code Block
msg.pagePntr = 1;  // init page pointer to 1
msg.userDataArray = [];  // init aray
var moment = global.get('moment');
const now = moment();  // use moment to creat time 20 days earlier than today
const DaysAgo = now.subtract(20, "days").startOf("day").utc().toISOString

...

(

...

);

...

msg.startDate = DaysAgo;
return msg;

Image RemovedThe loop function node concatenates the results of each page until it collects all the data.

...

Code Block
var userData = msg.data.dynamicData.result;  // Get the results from dynamic data node.
if (userData.length > 0) {   // is there any data.
    msg.userDataArray = msg.userDataArray.concat(userData);  // append to the last array.
    msg.pagePntr = parseInt(msg.pagePntr) + 1;  // increment the page pointer.
   // node.warn('Next page ' + msg.pagePntr);
    if(msg.data.dynamicData.paging.hasMore.hasNext === false) {   // is there another page. if not exit loop
       return [null,msg]    
    } else {
        return [msg,null]  // get the next page of data.
    }
} else {
    return [null,msg]   // no data
}

...

View file
nameDynamic Data Manager Example1.json

Example 2

This example deals with the Read, OR condition, AND, NOT Equal.

You can get more query commands at https://docs.mongodb.com/manual/tutorial/query-documents/

...

Code Block
{
"$or": [{"runStatus": "start"}, {"acknowledge": "yes"}],    
  "runStatus": { "$ne": "Complete" },
"limit": 900,
"page": 1,
"sortBy": {"createdAt":-1}
} 

Create

Lets you create a new data item. If you don’t specify a project ID in the payload, the data is created as Global data.

...

If the field is available in the schema, you can update the content of that field will be updated with the content given in the using the payload. The _id is used to identify the data item (required item). The field that you want to update must be inside the data object.

For example,

Example 1

You can update the field value of hospitalCounty field in the following image, hospitalCounty is a field the schema using the below code.

Code Block
{
    "_id" : "61362fff4f3c310078f92dad",
    "data":{
        "hospitalCounty": "county"
    }
}

In the below image, a field name hospitalCounty is available in the schema and that will be updated with the data value county”.

...

Example 2

In this example user, each record has a unique id called a token, only one result will be returned and we are going to update the runStatus to Complete

...

Example 3

In this example, we will use the function node to construct the entire payload and content to be updated and push it to the Dynamic data manager node.

Consider the schema with the Boolean and Datetime fields and you wanted to format the datetime field before updating it.

Use the function node to format the date time and construct the msg.payload.data property as shown below.

Code Block
const moment = global.get("moment");
var currentTime = moment().format('LLLL')
msg.payload.data = {
    "_id" : "61362fff4f3c310078f92dad",
    "data":{
        "isActive": true,
        "lastContactedDate":currentTime
    }
};
return msg;

The _id property uniquely identifies the document and the data object contains the schema fields to be updated.

Update the Model and Action (update). Leave the Dynamic data manager node’s payload field empty as we have constructed the payload object in the function node.

...

Upsert

If multiple results are found for a query, the oldest data item gets updated.

...