# Mongodb3 node : how to pass information from function node

**URL:** https://discourse.nodered.org/t/mongodb3-node-how-to-pass-information-from-function-node/64197
**Category:** General
**Created:** [21 June 2022 08:43 UTC](https://discourse.nodered.org/t/mongodb3-node-how-to-pass-information-from-function-node/64197 "2022-06-21T08:43:49Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![bertaud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bertaud/32/80981_2.png) [@bertaud](https://discourse.nodered.org/u/bertaud)
#### Post date: [21 June 2022 08:43 UTC](https://discourse.nodered.org/t/mongodb3-node-how-to-pass-information-from-function-node/64197/1 "2022-06-21T08:43:49Z")

</div>

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

```auto
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;

```

---

<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: [21 June 2022 10:15 UTC](https://discourse.nodered.org/t/mongodb3-node-how-to-pass-information-from-function-node/64197/2 "2022-06-21T10:15:23Z")

</div>

have you tried

```auto
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` 😉  
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 ?)

---

<div class="post-metadata">

### Author: ![bertaud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bertaud/32/80981_2.png) [@bertaud](https://discourse.nodered.org/u/bertaud)
#### Post date: [21 June 2022 13:11 UTC](https://discourse.nodered.org/t/mongodb3-node-how-to-pass-information-from-function-node/64197/3 "2022-06-21T13:11:00Z")

</div>

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

---

<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: [21 June 2022 13:45 UTC](https://discourse.nodered.org/t/mongodb3-node-how-to-pass-information-from-function-node/64197/4 "2022-06-21T13:45:43Z")

</div>

what about `newMsg.uri` with `uri` **all lower case**

ps. this is like a dejavu from your [mysql2](https://discourse.nodered.org/t/node-red-contrib-mysql2-node/64096/4) thread 😉

---

<div class="post-metadata">

### Author: ![bertaud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bertaud/32/80981_2.png) [@bertaud](https://discourse.nodered.org/u/bertaud)
#### Post date: [22 June 2022 05:24 UTC](https://discourse.nodered.org/t/mongodb3-node-how-to-pass-information-from-function-node/64197/5 "2022-06-22T05:24:16Z")

</div>

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

```auto
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.

```

---

<div class="post-metadata">

### Author: ![bertaud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bertaud/32/80981_2.png) [@bertaud](https://discourse.nodered.org/u/bertaud)
#### Post date: [22 June 2022 05:51 UTC](https://discourse.nodered.org/t/mongodb3-node-how-to-pass-information-from-function-node/64197/6 "2022-06-22T05:51:54Z")

</div>

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

```auto
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.

```

---

<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: [22 June 2022 10:41 UTC](https://discourse.nodered.org/t/mongodb3-node-how-to-pass-information-from-function-node/64197/7 "2022-06-22T10:41:22Z")

</div>

Its not clear from the [documenation](https://flows.nodered.org/node/node-red-contrib-mongodb3) 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](https://discourse.nodered.org/t/problem-use-aggregate-with-mongodb3/64191))

I did some tests with the more recent and updated [node-red-node-mongodb](https://flows.nodered.org/node/node-red-node-mongodb)  
I think you should use this instead

---

<div class="post-metadata">

### Author: ![bertaud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bertaud/32/80981_2.png) [@bertaud](https://discourse.nodered.org/u/bertaud)
#### Post date: [22 June 2022 18:15 UTC](https://discourse.nodered.org/t/mongodb3-node-how-to-pass-information-from-function-node/64197/8 "2022-06-22T18:15:48Z")

</div>

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 ?

---

<div class="post-metadata">

### Author: ![bertaud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bertaud/32/80981_2.png) [@bertaud](https://discourse.nodered.org/u/bertaud)
#### Post date: [22 June 2022 18:20 UTC](https://discourse.nodered.org/t/mongodb3-node-how-to-pass-information-from-function-node/64197/9 "2022-06-22T18:20:18Z")

</div>

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

---

<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: [22 June 2022 18:20 UTC](https://discourse.nodered.org/t/mongodb3-node-how-to-pass-information-from-function-node/64197/10 "2022-06-22T18:20:29Z")

</div>

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`

---

<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: [21 August 2022 18:20 UTC](https://discourse.nodered.org/t/mongodb3-node-how-to-pass-information-from-function-node/64197/11 "2022-08-21T18:20:59Z")

</div>

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