Node-Red mongodb3 使用来自环境变量的 URL 连接数据库

Node-Red mongodb3 connect DB using URL from environment variable

我是 运行 Express 应用程序中嵌入的 Node-Red。还使用 'dotenv' 加载环境变量。

使用 MongoDB 和 'node-red-contrib-mongodb3' 进行存储。

一切正常。但是,我有不同的环境,每个环境都有不同的MongoDB。

我想从配置(.env 文件或环境文件)连接到 MongoDB。

类似的东西,在MongoDB配置节点URL输入框golbal.get('env').MONGODB_DEV_URL or msg.MONGODB_URL

尝试在 'mongodb3' 和 google 的文档中寻找选项,但仍然没有成功。任何帮助或指导将不胜感激。

来自 Node-RED docs

Any node property can be set with an environment variable by setting its value to a string of the form ${ENV_VAR}. When the runtime loads the flows, it will substitute the value of that environment variable before passing it to the node.

This only works if it replaces the entire property - it cannot be used to substitute just part of the value. For example, it is not possible to use CLIENT-${HOST}.