node-red-nodes
node-red-nodes copied to clipboard
MongoDB out node is not visible
Which node are you reporting an issue on?
node-red-node-mongodb
What are the steps to reproduce?
install node-red-node-mongodb from pallete
What happens?
It gets installed successfully but only mongodb in node is visible in sidebar.
What do you expect to happen?
I want mongodb out node.
Please tell us about your environment:
- [ ] Node-RED version: v2.2.2
- [ ] node.js version: v14.19.2
- [ ] npm version: v6.14.17
- [ ] Platform/OS: Linux Ubuntu 20.04
- [ ] Browser: Chrome
I also tried to install it from command line. It shows below output `$ npm install node-red-node-mongodb npm WARN [email protected] requires a peer of should@>= 8.x but none is installed. You must install peer dependencies yourself. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
Do you get any errors in the browser's JavaScript console?
Yes, Below error
Uncaught SyntaxError: Identifier 'oneditprepare' has already been declared at <anonymous>:1:1 at b (vendor.js?v=2.2.2:2:839) at Pe (vendor.js?v=2.2.2:2:48536) at s.fn.init.append (vendor.js?v=2.2.2:2:49887) at a (red.min.js?v=2.2.2:16:2661) at r (red.min.js?v=2.2.2:16:2912) at Object.success (red.min.js?v=2.2.2:16:8599) at c (vendor.js?v=2.2.2:2:28294) at Object.fireWith [as resolveWith] (vendor.js?v=2.2.2:2:29039) at l (vendor.js?v=2.2.2:2:79800) (anonymous) @ VM852:1 b @ vendor.js?v=2.2.2:2 Pe @ vendor.js?v=2.2.2:2 append @ vendor.js?v=2.2.2:2 a @ red.min.js?v=2.2.2:16 r @ red.min.js?v=2.2.2:16 success @ red.min.js?v=2.2.2:16 c @ vendor.js?v=2.2.2:2 fireWith @ vendor.js?v=2.2.2:2 l @ vendor.js?v=2.2.2:2 (anonymous) @ vendor.js?v=2.2.2:2 load (async) send @ vendor.js?v=2.2.2:2 ajax @ vendor.js?v=2.2.2:2 s.ajax @ vendor.js?v=2.2.2:4 (anonymous) @ red.min.js?v=2.2.2:16 success @ red.min.js?v=2.2.2:16 c @ vendor.js?v=2.2.2:2 fireWith @ vendor.js?v=2.2.2:2 l @ vendor.js?v=2.2.2:2 (anonymous) @ vendor.js?v=2.2.2:2 load (async) send @ vendor.js?v=2.2.2:2 ajax @ vendor.js?v=2.2.2:2 s.ajax @ vendor.js?v=2.2.2:4 (anonymous) @ red.min.js?v=2.2.2:16 loadNodeCatalog @ red.min.js?v=2.2.2:16 (anonymous) @ red.min.js?v=2.2.2:16 (anonymous) @ red.min.js?v=2.2.2:16 success @ red.min.js?v=2.2.2:16 c @ vendor.js?v=2.2.2:2 fireWith @ vendor.js?v=2.2.2:2 l @ vendor.js?v=2.2.2:2 (anonymous) @ vendor.js?v=2.2.2:2 load (async) send @ vendor.js?v=2.2.2:2 ajax @ vendor.js?v=2.2.2:2 s.ajax @ vendor.js?v=2.2.2:4 s @ red.min.js?v=2.2.2:16 (anonymous) @ red.min.js?v=2.2.2:16 n.onmessage @ red.min.js?v=2.2.2:16
which refers to here
` function oneditprepare() { $("#node-input-operation").change(function () { var id = $("#node-input-operation option:selected").val();
if (id === "update") {
$(".node-input-payonly").hide();
$(".node-input-upsert, .node-input-multi").show();
} else if (id === "delete") {
$(".node-input-payonly, .node-input-upsert, .node-input-multi").hide();
} else {
$(".node-input-payonly").show();
$(".node-input-upsert, .node-input-multi").hide();
}
});
$("#node-input-collection").change(function () {
if($("#node-input-collection").val() === "") {
$("#node-warning").show();
} else {
$("#node-warning").hide();
}
});
}
RED.nodes.registerType('mongodb out', {
category: 'storage-output',
color: "rgb(218, 196, 180)",
defaults: {
mongodb: {type: "mongodb", required: true},
name: {value: ""},
collection: {value: ""},
payonly: {value: false},
upsert: {value: false},
multi: {value: false},
operation: {value: "store"}
},
inputs: 1,
outputs: 0,
icon: "mongodb.png",
align: "right",
label: function() {
var mongoNode = RED.nodes.node(this.mongodb);
return this.name || (mongoNode ? mongoNode.label() + " " + this.collection : "mongodb");
},
labelStyle: function() {
return this.name ? "node_label_italic" : "";
},
oneditprepare: oneditprepare
});
`
Thanks - I can see the issue... The node is declaring its own oneditprepare function and polluting the global namespace with it. It must be clashing with another node you have installed that is doing the same.
The fix is to wrap it's definition in a closure to stop the global leak.
But it would be good to identify which other node you have installed that is also leaking that function.
Thanks @knolleary for quick response. Meanwhile I tried this node on docker based nodered and it is worling fine there. I need to figure it out on my local system as per your suggestion.
@akashtalole it would be useful to know which other nodes are installed on the node-red where this issue was first seen.
Thanks.