I have to access a MongoDB with a database that is dynamically defined.
I did install the node-red-node-mongodb but I see this is not possible as the database is static inside the configuration.
So I'm trying to recode that myself into a function node (but I'm far from being a JS expert).
But when I deploy (without having coded anything) I get that error message:
Error: Cannot find module '/data/node_modules/mongodb/index.js'. Please verify that the package.json has a valid "main" entry
Actually /data/node_modules/mongodb/package.json has "main": "lib/index.js"
Could anyone advise me what could be missing ?
I am surprised because I already did something similar to use aws-sdk with no problems and the package.json of aws-sdk has "main": "lib/aws.js"
So I don't understand why for mongodb it search the "main" in the main folder and not in "lib" while it works well with "aws-sdk"
Thanks but the problem is that I get the above error before adding any code in OnStart/OnMessage
I haven't tried to call MongoClient yet.
I just declared mongodb in the Setup tab of the function node.
If I do like you say without the module declared in Setup, then I get a "ReferenceError: mongodb is not defined (line 1, col 21)"
If I add mongodb to Setup, I'm back to my initial problem
Actually I'm running docker nodered-3.0.2-latest which is nodered-3.0.2-16, just because "latest" is the default one. So I believe I will soon be hit by the same problem when latest evolve to nodejs 18.