Hi Andy,
thanks a lot for your feedback ... as I expected handling of function is beyond my (low) knowledge level.
What I was successfully doing so far is retrieving a data set from LoRaWAN, generating a static _id for a certain device and writing it to a MongoDB through "save". As soon as the next data set arrives the same _id is being generated, the previous data set in MongoDB overwritten and I could present always the latest data set.
Now data sets from same device arrive but each set contains different infos and I want to present the combination of such infos by updating a document with the additional objects ....
I tried to put together the important parts of my process within a flow - so now trying first time to add a flow to a forum post ... cross fingers ...
BR, Matthias
[
{
"id": "66bf3280.eeb04c",
"type": "inject",
"z": "a6a7e3da.fa9b6",
"name": "Data Set 1",
"props": [
{
"p": "payload.mmi_DevEUI",
"v": "A81758FFFE04FCE5",
"vt": "str"
},
{
"p": "payload.ts",
"v": "",
"vt": "date"
},
{
"p": "payload.item1",
"v": "blabla",
"vt": "str"
},
{
"p": "payload.item2",
"v": "12345",
"vt": "num"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 140,
"y": 220,
"wires": [
[
"53da6288.39be74",
"ce4f669f.f95f"
]
]
},
{
"id": "481f2246.b8667c",
"type": "inject",
"z": "a6a7e3da.fa9b6",
"name": "Data Set 2",
"props": [
{
"p": "payload.mmi_DevEUI",
"v": "A81758FFFE04FCE5",
"vt": "str"
},
{
"p": "payload.ts",
"v": "",
"vt": "date"
},
{
"p": "payload.item3",
"v": "testtest",
"vt": "str"
},
{
"p": "payload.item4",
"v": "67890",
"vt": "num"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 140,
"y": 260,
"wires": [
[
"53da6288.39be74",
"82c502b4.6d8e48"
]
]
},
{
"id": "53da6288.39be74",
"type": "function",
"z": "a6a7e3da.fa9b6",
"name": "shorten deveui to 12 char",
"func": "var str = msg.payload.mmi_DevEUI;\n\nvar str_short_begin = str.slice(0, 6);\nvar str_short_end = str.slice(10, 16);\nvar str_short = str_short_begin + str_short_end;\n\nmsg.payload._id = str_short;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 350,
"y": 240,
"wires": [
[
"393a2e11.9e075a",
"fd507e0a.82d6a8"
]
]
},
{
"id": "393a2e11.9e075a",
"type": "objectid",
"z": "a6a7e3da.fa9b6",
"name": "generate _id from deveui",
"selectedProperty": "_id",
"x": 610,
"y": 240,
"wires": [
[
"a7c2887b.991c3"
]
]
},
{
"id": "ce4f669f.f95f",
"type": "debug",
"z": "a6a7e3da.fa9b6",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 290,
"y": 180,
"wires": []
},
{
"id": "82c502b4.6d8e48",
"type": "debug",
"z": "a6a7e3da.fa9b6",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 290,
"y": 300,
"wires": []
},
{
"id": "fd507e0a.82d6a8",
"type": "debug",
"z": "a6a7e3da.fa9b6",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 550,
"y": 180,
"wires": []
},
{
"id": "a7c2887b.991c3",
"type": "debug",
"z": "a6a7e3da.fa9b6",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 810,
"y": 180,
"wires": []
},
{
"id": "53472c44.bb002c",
"type": "function",
"z": "a6a7e3da.fa9b6",
"name": "updateMany",
"func": "let ObjectId = mongodb.ObjectId\n\nlet newMsg = {};\n\nnewMsg.query = { \"_id\": { \"$in\": [ObjectId(\"60000f1879d9790bac657a94\"), ObjectId(\"6000162079d9790bac657a95\")] } };\n\nnewMsg.payload = { \"$set\": { \"testField\": 888 } };\n \nreturn newMsg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 950,
"y": 240,
"wires": [
[]
]
},
{
"id": "d503d41c.0cb168",
"type": "mongodb out",
"z": "a6a7e3da.fa9b6",
"mongodb": "d5beac98.b8fba8",
"name": "mmiDevice ",
"collection": "test",
"payonly": true,
"upsert": true,
"multi": true,
"operation": "update",
"x": 1230,
"y": 240,
"wires": []
},
{
"id": "d5beac98.b8fba8",
"type": "mongodb",
"z": "",
"hostname": "localhost",
"topology": "direct",
"connectOptions": "useUnifiedTopology=true",
"port": "27017",
"db": "nodered",
"name": ""
}
]