Mongodb3 node : how to pass information from function node

i want to pass information in function node to a mongo node especially the server information (URI). What is the syntax to use in function node ?

i try following code but doesn't works

var URI= "mongodb://"+ mongo_Username + ":" + mongo_Password + "@" + mongo_Server + ":" + mongo_Port + "/lbs?authSource=" + mongo_authSource
newMsg.Server={"URI":URI}
newMsg.collection = 'supplyChainEventHistory';
newMsg.operation  = 'find.toArray';
newMsg.payload    = [{'assetIdentifier' : assetid, 'status': "ACTIVE",'profileId' : profileid},{sort:{timestamp:1}}];
return newMsg;

have you tried

newMsg = {};
newMsg.URI = "mongodb://"+ mongo_Username + ":" + mongo_Password + "@" + mongo_Server + ":" + mongo_Port + "/lbs?authSource=" + mongo_authSource
newMsg.collection = 'supplyChainEventHistory';
newMsg.operation  = 'find.toArray';
newMsg.payload    = [{'assetIdentifier' : assetid, 'status': "ACTIVE",'profileId' : profileid},{sort:{timestamp:1}}];
return newMsg;

newMsg.Server.URI not the same as newMsg.URI :wink:
also where are the mongo_Username , mongo_Password, mongo_Server etc variables comming from
are they part of the previous msg ? (are they defined in a part of the code that you havent shared ?)

yes the variables are defined
i have tried newMsg.Server newMsg.URI newMsg.Server.URI without any sucess

what about newMsg.uri with uri all lower case

ps. this is like a dejavu from your mysql2 thread :wink:

with newMsg.uri in lower case i have the following exception at startup seems it is not safe

Jun 22 06:00:47 ip-10-1-1-230.eu-west-3.compute.internal systemd[1]: Started Node-RED graphical event wiring tool.
Jun 22 06:00:49 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:49 - [info]
Jun 22 06:00:49 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: Welcome to Node-RED
Jun 22 06:00:49 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: ===================
Jun 22 06:00:49 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:49 - [info] Node-RED version: v2.2.2
Jun 22 06:00:49 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:49 - [info] Node.js  version: v16.14.2
Jun 22 06:00:49 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:49 - [info] Linux 3.10.0-1160.62.1.el7.x86_64 x64 LE
Jun 22 06:00:50 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:50 - [info] Loading palette nodes
Jun 22 06:00:53 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:53 - [info] mDashboard version 2.19.4-beta started at /mui
Jun 22 06:00:54 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:54 - [info] Dashboard version 3.1.7 started at /ui
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:55 - [info] Settings file  : /home/ec2-user/.node-red/settings.js
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:55 - [info] Context store  : 'memoryOnly' [module=memory]
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:55 - [info] Context store  : 'file' [module=localfilesystem]
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:55 - [info] User directory : /home/ec2-user/.node-red
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:55 - [warn] Projects disabled : editorTheme.projects.enabled=false
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:55 - [info] Flows file     : /home/ec2-user/.node-red/flows.json
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:55 - [info] Server now running at http://127.0.0.1:1880/
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:55 - [warn]
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: ---------------------------------------------------------------------
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: Your flow credentials file is encrypted using a system-generated key.
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: If the system-generated key is lost for any reason, your credentials
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: file will not be recoverable, you will have to delete it and re-enter
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: your credentials.
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: You should set your own key using the 'credentialSecret' option in
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: your settings file. Node-RED will then re-encrypt your credentials
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: file using your chosen key the next time you deploy a change.
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: ---------------------------------------------------------------------
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:55 - [info] Starting flows
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:55 - [error] [mongodb3 in:Mongo server] missing mongodb3 configuration
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:55 - [info] Started flows
Jun 22 06:00:55 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 06:00:55 - [error] [function:find.toArray] SyntaxError: Unexpected token '{' (
Jun 22 07:15:26 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 07:15:26 - [info] Stopping flows
Jun 22 07:15:26 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 07:15:26 - [info] Stopped flows
Jun 22 07:15:26 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 07:15:26 - [red] Uncaught Exception:
Jun 22 07:15:26 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: 22 Jun 07:15:26 - [error] Error: connect ECONNREFUSED 127.0.0.1:3306
Jun 22 07:15:26 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
Jun 22 07:15:26 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[553]: --------------------
Jun 22 07:15:26 ip-10-1-1-230.eu-west-3.compute.internal systemd[1]: nodered.service: main process exited, code=exited, status=1/FAILURE
Jun 22 07:15:26 ip-10-1-1-230.eu-west-3.compute.internal systemd[1]: Unit nodered.service entered failed state.
Jun 22 07:15:26 ip-10-1-1-230.eu-west-3.compute.internal systemd[1]: nodered.service failed.
Jun 22 07:15:46 ip-10-1-1-230.eu-west-3.compute.internal systemd[1]: nodered.service holdoff time over, scheduling restart.
Jun 22 07:15:46 ip-10-1-1-230.eu-west-3.compute.internal systemd[1]: Stopped Node-RED graphical event wiring tool.

sorry the trace is not the good one
the trace when i comment newMsg.uri=uri and i put directly information in URI field of mongo node

Jun 22 07:46:26 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[3693]: 22 Jun 07:46:26 - [info] Starting flows
Jun 22 07:46:26 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[3693]: 22 Jun 07:46:26 - [info] Started flows
Jun 22 07:46:26 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[3693]: (node:3693) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine
Jun 22 07:46:26 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[3693]: (Use `node --trace-warnings ...` to show where the warning was created)

the trace when i uncomment the newMsg.uri in function node and i retrieve information in URI field of mongo node 

Jun 22 07:49:39 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[3693]: 22 Jun 07:49:39 - [info] Stopping flows
Jun 22 07:49:40 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[3693]: 22 Jun 07:49:40 - [info] Stopped flows
Jun 22 07:49:40 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[3693]: 22 Jun 07:49:40 - [red] Uncaught Exception:
Jun 22 07:49:40 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[3693]: 22 Jun 07:49:40 - [error] Error: connect ECONNREFUSED 127.0.0.1:3306
Jun 22 07:49:40 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[3693]: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
Jun 22 07:49:40 ip-10-1-1-230.eu-west-3.compute.internal Node-RED[3693]: --------------------
Jun 22 07:49:40 ip-10-1-1-230.eu-west-3.compute.internal systemd[1]: nodered.service: main process exited, code=exited, status=1/FAILURE
Jun 22 07:49:40 ip-10-1-1-230.eu-west-3.compute.internal systemd[1]: Unit nodered.service entered failed state.
Jun 22 07:49:40 ip-10-1-1-230.eu-west-3.compute.internal systemd[1]: nodered.service failed.

Its not clear from the documenation of the mongodb3 node that you can dynamically pass a URI for the db. maybe its not supported.

The node hasnt been updated for more than 3 years and very recently another user was getting errors with the aggregation option of the same node (forum post)

I did some tests with the more recent and updated node-red-node-mongodb
I think you should use this instead

im ok to use a recent and updated [node-red-node-mongodb] but i don't see more explanation on how to pass parameter to the node have you try this ?

as i see host is mandatory to be filled in the[node-red-node-mongodb node so no way to pass it in parameter ?

What parameters ?
If you are talking about the db connection string .. well .. you cannot change it.
It just gives you an option in the node's config to configure it .. but you wont be able to dynamically change it. You can change the collection though with msg.collection

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