-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathobjectid.js
More file actions
32 lines (24 loc) · 697 Bytes
/
objectid.js
File metadata and controls
32 lines (24 loc) · 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
let ObjectID = require('bson').ObjectID;
module.exports = function(RED) {
function ObjectIdNode(config) {
RED.nodes.createNode(this, config);
this.name = config.name;
this.property = config.property || 'payload';
this.on('input', msg=> {
let value;
try {
value = RED.util.getMessageProperty(msg, this.property);
}
catch (e) {}
if (Array.isArray(value)) {
value = value.map(value=> new ObjectID(value));
}
else {
value = new ObjectID(value);
}
RED.util.setMessageProperty(msg, this.property, value, true);
this.send(msg);
});
}
RED.nodes.registerType('objectid', ObjectIdNode);
}