Versions Compared

Key

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

...

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 donerequests, in case you make a mistake and created an infinite loop. Then either change the delay to 1 ms, or remove the delay completely.

...

The Dynamic Data Manager mode is set to Read.
AND condition of version, CreatedAt, Page
limit says for this page do not bring back more than 999 items. Which is the max limit.

...

Ignore the red X in this example, the validation is confused by the mustache tag, it msg.pagePnter is ultimately a number. sortBy, in this case we used createdAt. createdAt & modifiedAt & _id are always returned in the collection.

Code Block
{
  "version": "1",
  "createdAt": { "$gt" : "{{msg.startDate}}" },
  "limit": 999,
  "page": {{msg.pagePntr}},
  "sortBy": {"createdAt":-1}
} 

The init function node sets 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();
node.warn(DaysAgo);  // "2020-11-16T00:00:00.000Z"
msg.startDate = DaysAgo;
return msg;

The 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
}

...

If the field is available in the schema, the content of that field will be updated with the content given in the payload. The _id is used to identify the data item (required). The field that you want to update must be inside the data object. For example, in the following image, hospitalCounty is a field available in the schema that will be updated with the data “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

...

Upsert

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

...