steineey / node-red-contrib-mongodb4

MongoDB driver node for Node-RED
MIT License
26 stars 10 forks source link

[reopened] Automatic Re-connection to MongoDB on Node-RED Startup - v2.2.1 #21

Closed polu-im closed 1 year ago

polu-im commented 1 year ago

I refer to my old closed issue #20

Hi steineey,

thanks for your replay, i've tested this version (v2.2.1) but unfortunately it doesn't seem to be functioning as expected. I've done some tests and with MongoDB service stopped, it returns an "connect ETIMEDOUT" error (with node status reporting "operation failed") followed by a "Topology is closed" error (if i trigger a new mongodb query), which is the correct behavior when the database is offline. Unfortunately, even after starting the database service, the Topology error persists and the node status still reporting "operation failed".

image

If i restart Node-Red or re-deploy the flows, the MongoDB node start working as expected.

To reproduce the error I did the following steps:

  1. Turned off the MongoDB service and restarted Node-RED.
  2. Executed a query on MongoDB through Node-RED.
  3. Waited for the initial "operation failed".
  4. Started the MongoDB service.
  5. Attempted to perform a new query on MongoDB via Node-RED.

Here an example flow with the basic config i use for Node-Red:

[
    {
        "id": "c2a7c2a49b026b4f",
        "type": "mongodb4",
        "z": "b2dbc784a62faa82",
        "clientNode": "56940934ae60a779",
        "mode": "collection",
        "collection": "TEST",
        "operation": "findOne",
        "output": "toArray",
        "maxTimeMS": "",
        "handleDocId": false,
        "name": "",
        "x": 500,
        "y": 440,
        "wires": [
            [
                "058529797128eb9f"
            ]
        ]
    },
    {
        "id": "604ed2e4f2616592",
        "type": "inject",
        "z": "b2dbc784a62faa82",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 160,
        "y": 440,
        "wires": [
            [
                "71998d2ef11883d1"
            ]
        ]
    },
    {
        "id": "058529797128eb9f",
        "type": "debug",
        "z": "b2dbc784a62faa82",
        "name": "debug 13",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 440,
        "wires": []
    },
    {
        "id": "71998d2ef11883d1",
        "type": "function",
        "z": "b2dbc784a62faa82",
        "name": "function",
        "func": "msg.payload = { ID_VALUE: 100 };\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 320,
        "y": 440,
        "wires": [
            [
                "c2a7c2a49b026b4f"
            ]
        ]
    },
    {
        "id": "56940934ae60a779",
        "type": "mongodb4-client",
        "name": "MongoDB test",
        "protocol": "mongodb",
        "hostname": "192.168.0.100",
        "port": "27017",
        "dbName": "TEST",
        "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"
    }
]

I appreciate your attention to this matter and would be grateful for any further assistance or suggestions.

Best regards, polu

steineey commented 1 year ago

Hi polu,

thank you for testing and feedback. I can reproduce your error. Please check out this fix node-red-contrib-mongodb4@2.2.2-dev.

polu-im commented 1 year ago

Hi Steineey,

I have tested your new version in various scenarios, and it works perfectly! Thank you so much for your efforts. I'm eagerly looking forward to the final version being available on the Node-RED repository (the current available version is v2.0.0) and npm.

Best regards, Polu

steineey commented 1 year ago

Hi Polu,

thank you for testing. I published the final v2.2.2 and updated the Node-RED repository.

npm install --save --omit=dev node-red-contrib-mongodb4@2.2.2

Best regards Steineey