Data into dropdown

Hey, is there any solution where I can have the data of fields from mongodb which is installed in raspberry pi and place them into a dropdown . I'm new so is there someone who can guide me to achieve this .Thank u

show us the output of the mongodb response in a form that can be copied, and i or others will provide an example, also tell us which values from response you want in the dropdown msg.options.

The output for example:
Name: Maria
Age: 15
Subject: Math, Physics
Name: Alex
Age: 16
Subject: English
I want to have dropdowns named : Name and Age and Subjects
so the dropdown Name must have Maria and Alex
dropdown Age must have 15 and 16 ...
so dropdowns must have all the different data
Hope you understand what I mean by that

payload[0]

image
is that what you mean?

@E1cid is asking for sample data (as text, not a picture) - and asked you to use the "copy value" button and paste it as code between triple backticks </>

image

1 Like
[{"_id":"629e3912e99af917c68972d0","name":"Maria","age":"15","subject":"Math"},{"_id":"629e3928e99af917c68972d1","name":"Alex","age":"16","subject":"English"}]

Here is it

Thank u so much

[{"id":"334d337d.3c77fc","type":"inject","z":"692c6984.8f8378","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"_id\":\"629e3912e99af917c68972d0\",\"name\":\"Maria\",\"age\":\"15\",\"subject\":\"Math\"},{\"_id\":\"629e3928e99af917c68972d1\",\"name\":\"Alex\",\"age\":\"16\",\"subject\":\"English\"}]","payloadType":"json","x":190,"y":120,"wires":[["1966b1fb.4908a6","f2f7c76b.6e9bf8"]]},{"id":"1966b1fb.4908a6","type":"change","z":"692c6984.8f8378","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"$$.payload.name","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":220,"wires":[["b667ae2c.a4abc"]]},{"id":"f2f7c76b.6e9bf8","type":"change","z":"692c6984.8f8378","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"$$.payload.age","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":280,"wires":[["d46fdab7.f9935"]]},{"id":"b667ae2c.a4abc","type":"ui_dropdown","z":"692c6984.8f8378","name":"","label":"name","tooltip":"","place":"Select option","group":"2d4fe667.28f8ba","order":8,"width":0,"height":0,"passthru":true,"multiple":false,"options":[],"payload":"","topic":"topic","topicType":"msg","className":"","x":480,"y":220,"wires":[["7afbabb8.27e524"]]},{"id":"d46fdab7.f9935","type":"ui_dropdown","z":"692c6984.8f8378","name":"","label":"age","tooltip":"","place":"Select option","group":"2d4fe667.28f8ba","order":9,"width":0,"height":0,"passthru":true,"multiple":false,"options":[],"payload":"","topic":"topic","topicType":"msg","className":"","x":500,"y":280,"wires":[["7afbabb8.27e524"]]},{"id":"7afbabb8.27e524","type":"debug","z":"692c6984.8f8378","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":660,"y":100,"wires":[]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":1,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

An example with your data in the inject node
copy this and press ctrl i In the flow editor, paste and press import. Then press the inject node and then look at your dashboard for the dropdowns.

Thank u . it works fine but is there any other solution without copying that to the inject node . I mean directly without injecting it?

The inject node just simulates the result of your mongodb node attach the change nodes to you mongodb node.

For future reference it is best to supply a simple flow with the data in an inject node, then people who wish to help only have to edit your flow. the more you help with data and how you wish the result formatted, the more people will jump in and help, also if you get a solution it is best to mark it for others in the future, with similar issues.

Use a ui-control node to trigger your mongodb node then when some one lands on the dashboard the dropdowns will be auto updated.

ui-control example, i had to simulate the mongodb as i do not have it installled. Replace template node with the nodes required to query db.

[{"id":"e7e59324.a665f","type":"ui_ui_control","z":"692c6984.8f8378","name":"","events":"connect","x":110,"y":80,"wires":[["6fe75907.ad2d38"]]},{"id":"6fe75907.ad2d38","type":"template","z":"692c6984.8f8378","name":"simulate mongiodb result","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"[{\"_id\":\"629e3912e99af917c68972d0\",\"name\":\"Maria\",\"age\":\"15\",\"subject\":\"Math\"},{\"_id\":\"629e3928e99af917c68972d1\",\"name\":\"Alex\",\"age\":\"16\",\"subject\":\"English\"}]","output":"json","x":240,"y":180,"wires":[["1966b1fb.4908a6","f2f7c76b.6e9bf8"]]},{"id":"1966b1fb.4908a6","type":"change","z":"692c6984.8f8378","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"$$.payload.name","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":220,"wires":[["b667ae2c.a4abc"]]},{"id":"f2f7c76b.6e9bf8","type":"change","z":"692c6984.8f8378","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"$$.payload.age","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":280,"wires":[["d46fdab7.f9935"]]},{"id":"b667ae2c.a4abc","type":"ui_dropdown","z":"692c6984.8f8378","name":"","label":"name","tooltip":"","place":"Select option","group":"2d4fe667.28f8ba","order":8,"width":0,"height":0,"passthru":true,"multiple":false,"options":[],"payload":"","topic":"topic","topicType":"msg","className":"","x":480,"y":220,"wires":[["7afbabb8.27e524"]]},{"id":"d46fdab7.f9935","type":"ui_dropdown","z":"692c6984.8f8378","name":"","label":"age","tooltip":"","place":"Select option","group":"2d4fe667.28f8ba","order":9,"width":0,"height":0,"passthru":true,"multiple":false,"options":[],"payload":"","topic":"topic","topicType":"msg","className":"","x":500,"y":280,"wires":[["7afbabb8.27e524"]]},{"id":"7afbabb8.27e524","type":"debug","z":"692c6984.8f8378","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":660,"y":100,"wires":[]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":1,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

it works fine but when I add another document it doesn't added automatically to the dropdown

Use a ui-control node to trigger your mongodb node then when some one lands on the dashboard the dropdowns will be auto updated.
Can you please explain me how to do it :sweat_smile:
I need to do so

I copy it but I got empty dropdowns :confused:

sorry but I just have copied ur example and replace the template with mongodb node

[
    {
        "id": "5ca821d075388ef8",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "ae816914c2834490",
        "type": "ui_ui_control",
        "z": "5ca821d075388ef8",
        "name": "",
        "events": "connect",
        "x": 220,
        "y": 800,
        "wires": [
            [
                "6b11ea195295fa40"
            ]
        ]
    },
    {
        "id": "3038b37c4e9a9468",
        "type": "change",
        "z": "5ca821d075388ef8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "options",
                "pt": "msg",
                "to": "$$.payload.name",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 390,
        "y": 940,
        "wires": [
            [
                "3a3140796502d60e"
            ]
        ]
    },
    {
        "id": "9d33eff08f0812a4",
        "type": "change",
        "z": "5ca821d075388ef8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "options",
                "pt": "msg",
                "to": "$$.payload.age",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 390,
        "y": 1000,
        "wires": [
            [
                "35bba1967152dd05"
            ]
        ]
    },
    {
        "id": "3a3140796502d60e",
        "type": "ui_dropdown",
        "z": "5ca821d075388ef8",
        "name": "",
        "label": "name",
        "tooltip": "",
        "place": "Select option",
        "group": "2d4fe667.28f8ba",
        "order": 8,
        "width": 0,
        "height": 0,
        "passthru": true,
        "multiple": false,
        "options": [],
        "payload": "",
        "topic": "topic",
        "topicType": "msg",
        "className": "",
        "x": 590,
        "y": 940,
        "wires": [
            [
                "5da7e79dba81c06f"
            ]
        ]
    },
    {
        "id": "35bba1967152dd05",
        "type": "ui_dropdown",
        "z": "5ca821d075388ef8",
        "name": "",
        "label": "age",
        "tooltip": "",
        "place": "Select option",
        "group": "2d4fe667.28f8ba",
        "order": 9,
        "width": 0,
        "height": 0,
        "passthru": true,
        "multiple": false,
        "options": [],
        "payload": "",
        "topic": "topic",
        "topicType": "msg",
        "className": "",
        "x": 610,
        "y": 1000,
        "wires": [
            [
                "5da7e79dba81c06f"
            ]
        ]
    },
    {
        "id": "5da7e79dba81c06f",
        "type": "debug",
        "z": "5ca821d075388ef8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 860,
        "wires": []
    },
    {
        "id": "6b11ea195295fa40",
        "type": "mongodb-node",
        "z": "5ca821d075388ef8",
        "mongodb": "a01ab8825d064c0b",
        "name": "",
        "collection": "students",
        "operation": "find",
        "upsert": false,
        "multi": false,
        "x": 230,
        "y": 880,
        "wires": [
            [
                "3038b37c4e9a9468",
                "9d33eff08f0812a4"
            ]
        ]
    },
    {
        "id": "2d4fe667.28f8ba",
        "type": "ui_group",
        "name": "demo",
        "tab": "1caa8458.b17814",
        "order": 1,
        "disp": true,
        "width": "12",
        "collapse": false
    },
    {
        "id": "a01ab8825d064c0b",
        "type": "mongodb-config",
        "hostname": "127.0.0.1",
        "port": "27017",
        "db": "myDB",
        "name": ""
    },
    {
        "id": "1caa8458.b17814",
        "type": "ui_tab",
        "name": "Demo",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

another issue it that when I have two similiar data (eg : I have two students with the age 15) it dipslayed twice (double 15) in dropdown so how even when I have similiar data it dispalyes once? how can I prevent redundancy.
thank u for ur help and ur time I really appreciate it

$distinct($$.payload.age)

Jsonata has a distinct function.

You need to answer my question about mongodb if you require help with it. supply your original flow so I can see how you use mongodb.

okay can you please help me fix the redundancy and update problem ?
thank u

I didn't understand what u mean.. I already paste my flow above .. it works fine without ui-control but when I add it it displays nothing ..

[
    {
        "id": "5ca821d075388ef8",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "ae816914c2834490",
        "type": "ui_ui_control",
        "z": "5ca821d075388ef8",
        "name": "",
        "events": "connect",
        "x": 220,
        "y": 800,
        "wires": [
            [
                "6b11ea195295fa40"
            ]
        ]
    },
    {
        "id": "3038b37c4e9a9468",
        "type": "change",
        "z": "5ca821d075388ef8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "options",
                "pt": "msg",
                "to": "$$.payload.name",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 390,
        "y": 940,
        "wires": [
            [
                "3a3140796502d60e"
            ]
        ]
    },
    {
        "id": "9d33eff08f0812a4",
        "type": "change",
        "z": "5ca821d075388ef8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "options",
                "pt": "msg",
                "to": "$$.payload.age",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 390,
        "y": 1000,
        "wires": [
            [
                "35bba1967152dd05"
            ]
        ]
    },
    {
        "id": "3a3140796502d60e",
        "type": "ui_dropdown",
        "z": "5ca821d075388ef8",
        "name": "",
        "label": "name",
        "tooltip": "",
        "place": "Select option",
        "group": "2d4fe667.28f8ba",
        "order": 8,
        "width": 0,
        "height": 0,
        "passthru": true,
        "multiple": false,
        "options": [],
        "payload": "",
        "topic": "topic",
        "topicType": "msg",
        "className": "",
        "x": 590,
        "y": 940,
        "wires": [
            [
                "5da7e79dba81c06f"
            ]
        ]
    },
    {
        "id": "35bba1967152dd05",
        "type": "ui_dropdown",
        "z": "5ca821d075388ef8",
        "name": "",
        "label": "age",
        "tooltip": "",
        "place": "Select option",
        "group": "2d4fe667.28f8ba",
        "order": 9,
        "width": 0,
        "height": 0,
        "passthru": true,
        "multiple": false,
        "options": [],
        "payload": "",
        "topic": "topic",
        "topicType": "msg",
        "className": "",
        "x": 610,
        "y": 1000,
        "wires": [
            [
                "5da7e79dba81c06f"
            ]
        ]
    },
    {
        "id": "5da7e79dba81c06f",
        "type": "debug",
        "z": "5ca821d075388ef8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 860,
        "wires": []
    },
    {
        "id": "6b11ea195295fa40",
        "type": "mongodb-node",
        "z": "5ca821d075388ef8",
        "mongodb": "a01ab8825d064c0b",
        "name": "",
        "collection": "students",
        "operation": "find",
        "upsert": false,
        "multi": false,
        "x": 230,
        "y": 880,
        "wires": [
            [
                "3038b37c4e9a9468",
                "9d33eff08f0812a4"
            ]
        ]
    },
    {
        "id": "2d4fe667.28f8ba",
        "type": "ui_group",
        "name": "demo",
        "tab": "1caa8458.b17814",
        "order": 1,
        "disp": true,
        "width": "12",
        "collapse": false
    },
    {
        "id": "a01ab8825d064c0b",
        "type": "mongodb-config",
        "hostname": "127.0.0.1",
        "port": "27017",
        "db": "myDB",
        "name": ""
    },
    {
        "id": "1caa8458.b17814",
        "type": "ui_tab",
        "name": "Demo",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

My example did not have a function.

I asked for yoyur original flow where you got the data example i first asked for. The flows you posted were my examples of using drop down, but with a db node not a template. I want to see how the db node worked and how you retrevied data that now you seem unable to get.

[
    {
        "id": "25f80f7eb748b47a",
        "type": "tab",
        "label": "Flow 3",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "f5d5bbc2b33b78b2",
        "type": "inject",
        "z": "25f80f7eb748b47a",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 210,
        "y": 180,
        "wires": [
            [
                "b9a2c0016f7f7d65"
            ]
        ]
    },
    {
        "id": "b9a2c0016f7f7d65",
        "type": "mongodb-node",
        "z": "25f80f7eb748b47a",
        "mongodb": "a01ab8825d064c0b",
        "name": "",
        "collection": "students",
        "operation": "find",
        "upsert": false,
        "multi": false,
        "x": 510,
        "y": 220,
        "wires": [
            [
                "79bf4a4e987c9a3f"
            ]
        ]
    },
    {
        "id": "79bf4a4e987c9a3f",
        "type": "debug",
        "z": "25f80f7eb748b47a",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 830,
        "y": 200,
        "wires": []
    },
    {
        "id": "a01ab8825d064c0b",
        "type": "mongodb-config",
        "hostname": "127.0.0.1",
        "port": "27017",
        "db": "myDB",
        "name": ""
    }
]

Is that what you mean?
I only need to how to update automatically the dropdown

In your original flow you inject payload true. That is only difference
try

[{"id":"27a0a170.6ece86","type":"ui_ui_control","z":"2356cb00.dc20c6","name":"","events":"connect","x":220,"y":800,"wires":[["c102bb19.6a33a"]]},{"id":"c102bb19.6a33a","type":"change","z":"2356cb00.dc20c6","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":200,"y":840,"wires":[["96ba1b84.982f4"]]},{"id":"96ba1b84.982f4","type":"mongodb-node","z":"2356cb00.dc20c6","mongodb":"a01ab8825d064c0b","name":"","collection":"students","operation":"find","upsert":false,"multi":false,"x":230,"y":880,"wires":[["82f81638.889cb8","a3326a8e.d51b78"]]},{"id":"82f81638.889cb8","type":"change","z":"2356cb00.dc20c6","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"$$.payload.name","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":940,"wires":[["d06031f.049da5"]]},{"id":"a3326a8e.d51b78","type":"change","z":"2356cb00.dc20c6","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"$$.payload.age","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":1000,"wires":[["2f86c627.8a1842"]]},{"id":"d06031f.049da5","type":"ui_dropdown","z":"2356cb00.dc20c6","name":"","label":"name","tooltip":"","place":"Select option","group":"2d4fe667.28f8ba","order":8,"width":0,"height":0,"passthru":true,"multiple":false,"options":[],"payload":"","topic":"topic","topicType":"msg","className":"","x":590,"y":940,"wires":[["f30747cf.fa7c68"]]},{"id":"2f86c627.8a1842","type":"ui_dropdown","z":"2356cb00.dc20c6","name":"","label":"age","tooltip":"","place":"Select option","group":"2d4fe667.28f8ba","order":9,"width":0,"height":0,"passthru":true,"multiple":false,"options":[],"payload":"","topic":"topic","topicType":"msg","className":"","x":610,"y":1000,"wires":[["f30747cf.fa7c68"]]},{"id":"f30747cf.fa7c68","type":"debug","z":"2356cb00.dc20c6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":860,"wires":[]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":1,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]