[CCSDK-28] populated the seed code for dgbuilder
[ccsdk/distribution.git] / dgbuilder / core_nodes / storage / 66-mongodb.html
1 <!--
2   Copyright 2013,2014 IBM Corp.
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8   http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15 -->
16
17 <script type="text/x-red" data-template-name="mongodb">
18     <div class="form-row">
19         <label for="node-config-input-hostname"><i class="fa fa-bookmark"></i> Host</label>
20         <input class="input-append-left" type="text" id="node-config-input-hostname" placeholder="localhost" style="width: 40%;" >
21         <label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label>
22         <input type="text" id="node-config-input-port" placeholder="27017" style="width:45px">
23     </div>
24     <div class="form-row">
25         <label for="node-config-input-db"><i class="fa fa-database"></i> Database</label>
26         <input type="text" id="node-config-input-db" placeholder="test">
27     </div>
28     <div class="form-row">
29         <label for="node-config-input-user"><i class="fa fa-user"></i> Username</label>
30         <input type="text" id="node-config-input-user">
31     </div>
32     <div class="form-row">
33         <label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
34         <input type="password" id="node-config-input-password">
35     </div>
36     <div class="form-row">
37         <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
38         <input type="text" id="node-config-input-name" placeholder="Name">
39     </div>
40 </script>
41
42 <script type="text/javascript">
43     RED.nodes.registerType('mongodb', {
44         category: 'config',
45         color: "rgb(218, 196, 180)",
46         defaults: {
47             hostname: {value: "127.0.0.1", required: true},
48             port: {value: 27017, required: true},
49             db: {value: "", required: true},
50             name: {value: ""}
51         },
52         credentials: {
53             user: {type: "text"},
54             password: {type: "password"}
55         },
56         label: function() {
57             return this.name || this.hostname + ":" + this.port + "/" + this.db;
58         }
59     });
60 </script>
61
62
63 <script type="text/x-red" data-template-name="mongodb out">
64     <div class="form-row">
65         <label for="node-input-mongodb"><i class="fa fa-bookmark"></i> Server</label>
66         <input type="text" id="node-input-mongodb">
67     </div>
68     <div class="form-row">
69         <label for="node-input-collection"><i class="fa fa-briefcase"></i> Collection</label>
70         <input type="text" id="node-input-collection" placeholder="collection">
71     </div>
72     <div class="form-row">
73         <label for="node-input-operation"><i class="fa fa-wrench"></i> Operation</label>
74         <select type="text" id="node-input-operation" style="display: inline-block; vertical-align: top;">
75             <option value="store">save</option>
76             <option value="insert">insert</option>
77             <option value="update">update</option>
78             <option value="delete">remove</option>
79         </select>
80     </div>
81     <div class="form-row node-input-payonly">
82         <label>&nbsp;</label>
83         <input type="checkbox" id="node-input-payonly" placeholder="Only" style="display: inline-block; width: auto; vertical-align: top;">
84         <label for="node-input-payonly" style="width: 70%;">Only store msg.payload object</label>
85     </div>
86     <div class="form-row node-input-upsert">
87         <label>&nbsp;</label>
88         <input type="checkbox" id="node-input-upsert" placeholder="Only" style="display: inline-block; width: auto; vertical-align: top;">
89         <label for="node-input-upsert" style="width: 70%;">Create a new document if no match found</label>
90     </div>
91     <div class="form-row node-input-multi">
92         <label>&nbsp;</label>
93         <input type="checkbox" id="node-input-multi" placeholder="Only" style="display: inline-block; width: auto; vertical-align: top;;">
94         <label for="node-input-multi" style="width: 70%;">Update all matching documents</label>
95     </div>
96     <div class="form-row">
97         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
98         <input type="text" id="node-input-name" placeholder="Name">
99     </div>
100     <div class="form-tips" id="node-warning" style="display: none"><b> Tip:</b> If no collection is set, ensure <b>msg.collection</b> will contain the collection name
101     </div>
102 </script>
103
104 <script type="text/x-red" data-help-name="mongodb out">
105     <p>A simple MongoDB output node. Can save, insert, update and remove objects from a chosen collection.</p>
106     <p>Save will update an existing object or insert a new object if one does not already exist.</p>
107     <p>Insert will insert a new object.</p>
108     <p>Save and insert either store <b>msg</b> or <b>msg.payload</b>.</p>
109     <p>Update will modify an existing object or objects. The query to select objects to update uses <b>msg.query</b> and the update to the element uses <b>msg.payload</b>.</p>
110     <p>Update can add a object if it does not exist or update multiple objects.</p>
111     <p>Remove will remove objects that match the query passed in on <b>msg.payload</b>. A blank query will delete <i>all of the objects</i> in the collection.</p>
112     <p>You can either set the collection method in the node config or on <b>msg.collection</b>. Setting it in the node will override <b>msg.collection</b>.</p>
113     <p>By default MongoDB creates an <i>_id</i> property as the primary key - so repeated injections of the same <b>msg</b> will result in many database entries.</p>
114     <p>If this is NOT the desired behaviour - ie. you want repeated entries to overwrite, then you must set the <b>msg._id</b> property to be a constant by the use of a previous function node.</p>
115     <p>This could be a unique constant or you could create one based on some other msg property.</p>
116     <p>Currently we do not limit or cap the collection size at all... this may well change.</p>
117 </script>
118
119 <script type="text/javascript">
120
121     function oneditprepare() {
122         $("#node-input-operation").change(function () {
123             var id = $("#node-input-operation option:selected").val();
124
125             if (id === "update") {
126                 $(".node-input-payonly").hide();
127                 $(".node-input-upsert, .node-input-multi").show();
128             } else if (id === "delete") {
129                 $(".node-input-payonly, .node-input-upsert, .node-input-multi").hide();
130             } else {
131                 $(".node-input-payonly").show();
132                 $(".node-input-upsert, .node-input-multi").hide();
133             }
134         });
135
136         $("#node-input-collection").change(function () {
137             if($("#node-input-collection").val() === "") {
138                 $("#node-warning").show();
139             } else {
140                 $("#node-warning").hide();
141             }
142         });
143     }
144
145     RED.nodes.registerType('mongodb out', {
146         category: 'storage-output',
147         color: "rgb(218, 196, 180)",
148         defaults: {
149             mongodb: {type: "mongodb", required: true},
150             name: {value: ""},
151             collection: {value: ""},
152             payonly: {value: false},
153             upsert: {value: false},
154             multi: {value: false},
155             operation: {value: "store"}
156         },
157         inputs: 1,
158         outputs: 0,
159         icon: "mongodb.png",
160         align: "right",
161         label: function() {
162             var mongoNode = RED.nodes.node(this.mongodb);
163             return this.name || (mongoNode ? mongoNode.label() + " " + this.collection: "mongodb");
164         },
165         labelStyle: function() {
166             return this.name ? "node_label_italic" : "";
167         },
168         oneditprepare: oneditprepare
169     });
170 </script>
171
172
173 <script type="text/x-red" data-template-name="mongodb in">
174     <div class="form-row">
175         <label for="node-input-mongodb"><i class="fa fa-bookmark"></i> Server</label>
176         <input type="text" id="node-input-mongodb">
177     </div>
178     <div class="form-row">
179         <label for="node-input-collection"><i class="fa fa-briefcase"></i> Collection</label>
180         <input type="text" id="node-input-collection" placeholder="collection">
181     </div>
182     <div class="form-row">
183         <label for="node-input-operation"><i class="fa fa-wrench"></i> Operation</label>
184         <select type="text" id="node-input-operation" style="display: inline-block; vertical-align: top;">
185             <option value="find">find</option>
186             <option value="count">count</option>
187             <option value="aggregate">aggregate</option>
188         </select>
189     </div>
190     <div class="form-row">
191         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
192         <input type="text" id="node-input-name" placeholder="Name">
193     </div>
194     <div class="form-tips" id="node-warning" style="display: none"><b> Tip:</b> If no collection is set, ensure <b>msg.collection</b> will contain the collection name
195     </div>
196 </script>
197
198 <script type="text/x-red" data-help-name="mongodb in">
199     <p>Calls a MongoDB collection method based on the selected operator.</p>
200     <p>Find queries a collection using the <b>msg.payload</b> as the query statement as per the .find() function. Optionally, you may also (via a function) set a <b>msg.projection</b> object to constrain the returned fields, a <b>msg.sort</b> object and a <b>msg.limit</b> object.</p>
201     <p>Count returns a count of the number of documents in a collection or matching a query using the <b>msg.payload</b> as the query statement.</p>
202     <p>Aggregate provides access to the aggregation pipeline using the <b>msg.payload</b> as the pipeline array.</p>
203     <p>You can override the collection the method is performed on by setting <b>msg.collection</b> to the desired collection name.</p>
204     <p>See the <a href="http://docs.mongodb.org/manual/reference/method/db.collection.find/" target="new"><i>MongoDB collection methods docs</i></a> for examples.</p>
205     <p>The result is returned in <b>msg.payload</b>.</p>
206 </script>
207
208 <script type="text/javascript">
209
210     RED.nodes.registerType('mongodb in', {
211         category: 'storage-input',
212         color: "rgb(218, 196, 180)",
213         defaults: {
214             mongodb: {type: "mongodb", required: true},
215             name: {value: ""},
216             collection: {value: ""},
217             operation: {value: "find"}
218         },
219         inputs: 1,
220         outputs: 1,
221         icon: "mongodb.png",
222         label: function() {
223             var mongoNode = RED.nodes.node(this.mongodb);
224             return this.name || (mongoNode ? mongoNode.label() + " " + this.collection: "mongodb");
225         },
226         labelStyle: function() {
227             return this.name ? "node_label_italic" : "";
228         },
229         oneditprepare: oneditprepare
230     });
231 </script>