Work with OpenFlow Entities in Node-RED

Hi there!

I want to ask how can I invoke or even rewrite datas from OpenFlow Entities using Node-RED.
For example: I need to store LastRun of a Robot and I decided to store it in Entities, collection “entities”. Now i need to read the data from it and rewrite. Thats all!

Thanks in advice!

you ca query the collection using Get
image
and once you have updated the entries, you can send it to “update”
image

Ok, i get how to configure api get node, but with api update node configurations i have problems.

In this screenshot I inject the flow creating an empty msg.payload, then recieving needed entity. For more clarity, here is api get config:

Also I get today date to rewrite the entity date. This all is to store in entity last run of specified robot.

After all changes with entity info recieved in my msg, I wanna update the entity with the payload i configurated, and here is the problem. How to config update node? If you can, please provide an example with what should i write in update node.

in nodered, as a rule f thumb you use msg.payload as the data you are working with and each node uses msg.payload as input and output.
If you need to save data that is not used by the next node, you save it somewhere else like msg.mydata
Changing that, is fine,but i highly recommend you do not do that, it will make it harder to read and troubleshoot your flows.

my api nodes always expect an array as input and gives an array back. For ease of use, if an api node received an object t converts it to an array and continues. So when you give the api update node a data it will fail, not sure why you was doing that ?

here is a basic example of how to insert and update an object

example workflow
[
    {
        "id": "1a904c0d8057d7e0",
        "type": "inject",
        "z": "562ba6bdfee8207a",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 200,
        "y": 4260,
        "wires": [
            [
                "577c268e71f1c871"
            ]
        ]
    },
    {
        "id": "577c268e71f1c871",
        "type": "api get",
        "z": "562ba6bdfee8207a",
        "name": "",
        "query": "{\"_type\": \"mytest\"}",
        "querytype": "str",
        "projection": "",
        "projectiontype": "str",
        "top": 500,
        "toptype": "num",
        "skip": 0,
        "skiptype": "num",
        "collection": "entities",
        "collectiontype": "str",
        "resultfield": "payload",
        "resultfieldtype": "msg",
        "orderby": "",
        "orderbytype": "str",
        "x": 350,
        "y": 4260,
        "wires": [
            [
                "5c124d3afc02ec74"
            ]
        ]
    },
    {
        "id": "11d0f40518266eaf",
        "type": "inject",
        "z": "562ba6bdfee8207a",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 200,
        "y": 4200,
        "wires": [
            [
                "9a35681bbdca2f22"
            ]
        ]
    },
    {
        "id": "94c92864069e1fb0",
        "type": "api addorupdate",
        "z": "562ba6bdfee8207a",
        "name": "",
        "writeconcern": "0",
        "journal": "false",
        "entitytype": "mytest",
        "entitytypetype": "str",
        "collection": "entities",
        "collectiontype": "str",
        "entities": "payload",
        "entitiestype": "msg",
        "uniqeness": "_type",
        "uniqenesstype": "str",
        "resultfield": "",
        "inputfield": "",
        "x": 540,
        "y": 4200,
        "wires": [
            [
                "ec7ec592fb74b023"
            ]
        ]
    },
    {
        "id": "9a35681bbdca2f22",
        "type": "function",
        "z": "562ba6bdfee8207a",
        "name": "function 86",
        "func": "msg.payload = {name: \"my test\", _type: \"mytest\"}\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 350,
        "y": 4200,
        "wires": [
            [
                "94c92864069e1fb0"
            ]
        ]
    },
    {
        "id": "93e513de68eb36d8",
        "type": "api update",
        "z": "562ba6bdfee8207a",
        "name": "",
        "entitytype": "",
        "entitytypetype": "str",
        "collection": "entities",
        "collectiontype": "str",
        "entities": "payload",
        "entitiestype": "msg",
        "writeconcern": "0",
        "journal": "false",
        "inputfield": "",
        "resultfield": "",
        "x": 690,
        "y": 4260,
        "wires": [
            [
                "51a26c9e8484d89b"
            ]
        ]
    },
    {
        "id": "5c124d3afc02ec74",
        "type": "function",
        "z": "562ba6bdfee8207a",
        "name": "function 87",
        "func": "msg.payload.filter(item=> {\n    item.name = item.name + \" updated\"\n})\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 510,
        "y": 4260,
        "wires": [
            [
                "93e513de68eb36d8"
            ]
        ]
    },
    {
        "id": "ec7ec592fb74b023",
        "type": "debug",
        "z": "562ba6bdfee8207a",
        "name": "debug 58",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload.0.name",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 720,
        "y": 4200,
        "wires": []
    },
    {
        "id": "51a26c9e8484d89b",
        "type": "debug",
        "z": "562ba6bdfee8207a",
        "name": "debug 59",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload.0.name",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 860,
        "y": 4260,
        "wires": []
    }
]

Wow, that helps a lot! Thank you very much! :heart:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.