# Help with listing mongoDB collections

**URL:** <https://discourse.nodered.org/t/help-with-listing-mongodb-collections/95886>\
**Category:** General\
**Tags:** function-node\
**Created:** [9 March 2025 14:20 UTC](https://discourse.nodered.org/t/help-with-listing-mongodb-collections/95886 "2025-03-09T14:20:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joaovitor](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Joaovitor](https://discourse.nodered.org/u/Joaovitor)\
**Post date:** [9 March 2025 14:20 UTC](https://discourse.nodered.org/t/help-with-listing-mongodb-collections/95886/1 "2025-03-09T14:20:55Z")

</div>

I am writing code for a small administrative database. One of the things I need from the database is the ability to list existing collections and list them in checkboxes. However, I am unable to do this. Attached is the code I am using. At this point, I just need an array containing the collections that are already registered. My flow is attached.

I am using node-red-contrib-mongodb4

````auto
    {
        "id": "f33ae0340cb92cfd",
        "type": "mongodb4",
        "z": "012812a26a41e597",
        "clientNode": "079563e7e443328f",
        "mode": "db",
        "collection": "",
        "operation": "getCollectionInfos",
        "output": "toArray",
        "maxTimeMS": "0",
        "handleDocId": false,
        "name": "",
        "x": 1170,
        "y": 360,
        "wires": [
            [
                "f652a658efb090bf"
            ]
        ]
    },
    {
        "id": "f652a658efb090bf",
        "type": "debug",
        "z": "012812a26a41e597",
        "name": "debug 5",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1380,
        "y": 360,
        "wires": []
    },
    {
        "id": "7105457f780bf9e4",
        "type": "inject",
        "z": "012812a26a41e597",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 800,
        "y": 360,
        "wires": [
            [
                "db80ab283244da62"
            ]
        ]
    },
    {
        "id": "db80ab283244da62",
        "type": "function",
        "z": "012812a26a41e597",
        "name": "Def. ",
        "func": "const query = {\n listCollections: 1.0,\n authorizedCollections: true,\n nameOnly: true\n};\n\nconst options = {}; \n\nmsg.payload = [query, options];\n\nreturn msg;\n",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 990,
        "y": 360,
        "wires": [
            [
                "f33ae0340cb92cfd"
            ]
        ]
    },
    {
        "id": "079563e7e443328f",
        "type": "mongodb4-client",
        "name": "",
        "protocol": "mongodb",
        "hostname": "",
        "port": "27017",
        "dbName": "Componentes",
        "appName": "",
        "authSource": "",
        "authMechanism": "DEFAULT",
        "tls": false,
        "tlsCAFile": "",
        "tlsCertificateKeyFile": "",
        "tlsInsecure": false,
        "connectTimeoutMS": "30000",
        "socketTimeoutMS": "0",
        "minPoolSize": "0",
        "maxPoolSize": "100",
        "maxIdleTimeMS": "0",
        "uri": "",
        "advanced": "{}",
        "uriTabActive": "tab-uri-simple"
    }
]```
````

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [9 March 2025 15:04 UTC](https://discourse.nodered.org/t/help-with-listing-mongodb-collections/95886/2 "2025-03-09T15:04:54Z")

</div>

Hi .. I managed to get a list of Collections by setting the Mode to **database operation**  
but the Operation i left blank and I set it in the Function node as `command` instead of `getCollectionInfos`

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/7/576d00848398af49395cd93b34ee91fc09bf63f8.png)

```auto
msg.operation = "command"
msg.payload = {
      listCollections: 1.0
}
   
return msg;

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 March 2025 15:05 UTC](https://discourse.nodered.org/t/help-with-listing-mongodb-collections/95886/3 "2025-03-23T15:05:20Z")

</div>

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