Skip to content

Commit 5a62f5b

Browse files
committed
Added missing operations to IN node
1 parent 44448bd commit 5a62f5b

File tree

2 files changed

+372
-241
lines changed

2 files changed

+372
-241
lines changed

storage/mongodb/66-mongodb.html

Lines changed: 86 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script type="text/x-red" data-template-name="mongodb-config">
1+
<script type="text/x-red" data-template-name="mongodb">
22
<div class="form-row">
33
<label for="node-config-input-hostname"><i class="fa fa-bookmark"></i> <span data-i18n="mongodb.label.host"></span></label>
44
<input class="input-append-left" type="text" id="node-config-input-hostname" placeholder="localhost" style="width: 40%;" >
@@ -24,7 +24,7 @@
2424
</script>
2525

2626
<script type="text/javascript">
27-
RED.nodes.registerType('mongodb-config', {
27+
RED.nodes.registerType('mongodb', {
2828
category: 'config',
2929
color: "rgb(218, 196, 180)",
3030
defaults: {
@@ -44,7 +44,7 @@
4444
</script>
4545

4646

47-
<script type="text/x-red" data-template-name="mongodb">
47+
<script type="text/x-red" data-template-name="mongodb out">
4848
<div class="form-row">
4949
<label for="node-input-mongodb"><i class="fa fa-bookmark"></i> <span data-i18n="mongodb.label.server"></span></label>
5050
<input type="text" id="node-input-mongodb">
@@ -56,10 +56,7 @@
5656
<div class="form-row">
5757
<label for="node-input-operation"><i class="fa fa-wrench"></i> <span data-i18n="mongodb.label.operation"></span></label>
5858
<select type="text" id="node-input-operation" style="display: inline-block; vertical-align: top;">
59-
<option value="find" data-i18n="mongodb.operation.find"></option>
60-
<option value="count" data-i18n="mongodb.operation.count"></option>
61-
<option value="aggregate" data-i18n="mongodb.operation.aggregate"></option>
62-
<option value="store" data-i18n="mongodb.operation.save"></option>
59+
<option value="store" data-i18n="mongodb.operation.save"></option>
6360
<option value="insert" data-i18n="mongodb.operation.insert"></option>
6461
<option value="update" data-i18n="mongodb.operation.update"></option>
6562
<option value="delete" data-i18n="mongodb.operation.remove"></option>
@@ -70,7 +67,7 @@
7067
<input type="checkbox" id="node-input-payonly" style="display: inline-block; width: auto; vertical-align: top;">
7168
<label for="node-input-payonly" style="width: 70%;"><span data-i18n="mongodb.label.onlystore"></span></label>
7269
</div>
73-
<div class="form-row node-input-upsert">
70+
<div class="form-row node-input-upsert">
7471
<label>&nbsp;</label>
7572
<input type="checkbox" id="node-input-upsert" style="display: inline-block; width: auto; vertical-align: top;">
7673
<label for="node-input-upsert" style="width: 70%;"><span data-i18n="mongodb.label.createnew"></span></label>
@@ -87,51 +84,29 @@
8784
<div class="form-tips" id="node-warning" style="display: none"><span data-i18n="[html]mongodb.tip"></span></div>
8885
</script>
8986

90-
<script type="text/x-red" data-help-name="mongodb">
91-
<p>A simple MongoDB node. Can manipulate a chosen collection.</p>
92-
93-
<p>Find queries a collection using the <code>msg.payload</code> as the query statement as per the .find() function.
94-
Optionally, you may also set a <code>msg.projection</code> object (via a function) to constrain the returned
95-
fields. You can also set a <code>msg.sort</code> object, a <code>msg.limit</code> number and a <code>msg.skip</code> number.</p>
96-
97-
<p>Count returns a count of the number of documents in a collection, or matches a query using the
98-
<code>msg.payload</code> as the query statement.</p>
99-
100-
<p>Aggregate provides access to the aggregation pipeline using the <code>msg.payload</code> as the pipeline array.</p>
101-
102-
103-
<p>Save will update an existing object or insert a new object if one does not already exist.</p>
104-
105-
<p>Insert will insert a new object.</p>
106-
107-
<p>Update will modify an existing object or objects. The query to select objects to update uses <code>msg.query</code>,
87+
<script type="text/x-red" data-help-name="mongodb out">
88+
<p>A simple MongoDB output node. Can save, insert, update and remove objects from a chosen collection.</p>
89+
<p>Save will update an existing object or insert a new object if one does not already exist.</p>
90+
<p>Insert will insert a new object.</p>
91+
<p>Save and insert either store <code>msg</code> or <code>msg.payload</code>.</p>
92+
<p>Update will modify an existing object or objects. The query to select objects to update uses <code>msg.query</code>,
10893
and the update to the element uses <code>msg.payload</code>. If <code>msg.query._id</code> is
10994
a valid mongo ObjectId string it will be converted to an ObjectId type.</p>
11095
<p>Update can add an object if it does not exist or update multiple objects.</p>
11196
<p>Remove will remove objects that match the query passed in on <code>msg.payload</code>. A blank query will delete
112-
<i>all of the objects</i> in the collection.</p>
113-
97+
<i>all of the objects</i> in the collection.</p>
11498
<p>You can either set the collection method in the node config or on <code>msg.collection</code>. Setting it in the
115-
node will override <code>msg.collection</code>.</p>
116-
117-
<p>See the <a href="http://docs.mongodb.org/manual/reference/method/db.collection.find/" target="new"><i>MongoDB
118-
collection methods docs</i></a> for examples.</p>
119-
<p>The result is returned in <code>msg.payload</code>.</p>
120-
99+
node will override <code>msg.collection</code>.</p>
121100
<p>By default, MongoDB creates an <i>_id</i> property as the primary key, so repeated injections of the
122-
same <code>msg</code> will result in many database entries.</p>
123-
101+
same <code>msg</code> will result in many database entries.</p>
124102
<p>If this is NOT the desired behaviour, i.e., you want repeated entries to overwrite, then you must set
125-
the <code>msg._id</code> property to be a constant by the use of a previous function node.</p>
126-
103+
the <code>msg._id</code> property to be a constant by the use of a previous function node.</p>
127104
<p>This could be a unique constant or you could create one based on some other msg property.</p>
128105
<p>Currently we do not limit or cap the collection size, however this may well change.</p>
129106
</script>
130107

131108
<script type="text/javascript">
132109

133-
134-
135110
function oneditprepare() {
136111
$("#node-input-operation").change(function () {
137112
var id = $("#node-input-operation option:selected").val();
@@ -156,17 +131,83 @@
156131
});
157132
}
158133

159-
RED.nodes.registerType('mongodb', {
160-
category: 'storage',
134+
RED.nodes.registerType('mongodb out', {
135+
category: 'storage-output',
161136
color: "rgb(218, 196, 180)",
162137
defaults: {
163-
mongodb: { type: "mongodb-config", required: true },
138+
mongodb: { type: "mongodb", required: true },
164139
name: { value: "" },
165140
collection: { value: "" },
166141
payonly: { value: false },
167-
operation: { value: "find" },
168142
upsert: { value: false },
169-
multi: { value: false }
143+
multi: { value: false },
144+
operation: { value: "store" }
145+
},
146+
inputs: 1,
147+
outputs: 0,
148+
icon: "mongodb.png",
149+
align: "right",
150+
label: function () {
151+
var mongoNode = RED.nodes.node(this.mongodb);
152+
return this.name || (mongoNode ? mongoNode.label() + " " + this.collection : "mongodb");
153+
},
154+
labelStyle: function () {
155+
return this.name ? "node_label_italic" : "";
156+
},
157+
oneditprepare: oneditprepare
158+
});
159+
</script>
160+
161+
162+
<script type="text/x-red" data-template-name="mongodb in">
163+
<div class="form-row">
164+
<label for="node-input-mongodb"><i class="fa fa-bookmark"></i> <span data-i18n="mongodb.label.server"></span></label>
165+
<input type="text" id="node-input-mongodb">
166+
</div>
167+
<div class="form-row">
168+
<label for="node-input-collection"><i class="fa fa-briefcase"></i> <span data-i18n="mongodb.label.collection"></span></label>
169+
<input type="text" id="node-input-collection">
170+
</div>
171+
<div class="form-row">
172+
<label for="node-input-operation"><i class="fa fa-wrench"></i> <span data-i18n="mongodb.label.operation"></span></label>
173+
<select type="text" id="node-input-operation" style="display: inline-block; vertical-align: top;">
174+
<option value="find" data-i18n="mongodb.operation.find"></option>
175+
<option value="count" data-i18n="mongodb.operation.count"></option>
176+
<option value="aggregate" data-i18n="mongodb.operation.aggregate"></option>
177+
</select>
178+
</div>
179+
<div class="form-row">
180+
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
181+
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
182+
</div>
183+
<div class="form-tips" id="node-warning" style="display: none"><span data-i18n="[html]mongodb.tip"></span></div>
184+
</script>
185+
186+
<script type="text/x-red" data-help-name="mongodb in">
187+
<p>Calls a MongoDB collection method based on the selected operator.</p>
188+
<p>Find queries a collection using the <code>msg.payload</code> as the query statement as per the .find() function.
189+
Optionally, you may also set a <code>msg.projection</code> object (via a function) to constrain the returned
190+
fields. You can also set a <code>msg.sort</code> object, a <code>msg.limit</code> number and a <code>msg.skip</code> number.</p>
191+
<p>Count returns a count of the number of documents in a collection, or matches a query using the
192+
<code>msg.payload</code> as the query statement.</p>
193+
<p>Aggregate provides access to the aggregation pipeline using the <code>msg.payload</code> as the pipeline array.</p>
194+
<p>You can either set the collection method in the node config or on <code>msg.collection</code>. Setting it in
195+
the node will override <code>msg.collection</code>.</p>
196+
<p>See the <a href="http://docs.mongodb.org/manual/reference/method/db.collection.find/" target="new"><i>MongoDB
197+
collection methods docs</i></a> for examples.</p>
198+
<p>The result is returned in <code>msg.payload</code>.</p>
199+
</script>
200+
201+
<script type="text/javascript">
202+
203+
RED.nodes.registerType('mongodb in', {
204+
category: 'storage-input',
205+
color: "rgb(218, 196, 180)",
206+
defaults: {
207+
mongodb: { type: "mongodb", required: true },
208+
name: { value: "" },
209+
collection: { value: "" },
210+
operation: { value: "find" }
170211
},
171212
inputs: 1,
172213
outputs: 1,

0 commit comments

Comments
 (0)