Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Inserts the `msg.payload` as document into a collection.

Looks for documents into a collection using `msg.payload` as predicate.

`msg.sort` (optional) to set sorting

`msg.limit` (optional) to define the maximum number of returned results (for paging)

`msg.skip` (optional) to define the number of results to skip (for paging)

## Update node

Updates a collection's documents. `msg.predicate` will be the filter and `msg.update` the update operation itself. `db.collection(collectionName).update(...)` is invoked using `{multi: true}`.
Expand Down
12 changes: 10 additions & 2 deletions find.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,13 @@
</script>

<script type="text/x-red" data-help-name="tingodb-find">
<p>Performs a .find query over a collection.</p>
</script>
<p>Performs a .find query over a collection</p>
<p>Options:
<ul>
<li>msg.payload (object) - <a href="https://docs.mongodb.com/drivers/node/current/fundamentals/crud/read-operations/retrieve/">define query</a></li>
<li>msg.sort (object) - <a href="https://docs.mongodb.com/drivers/node/current/fundamentals/crud/read-operations/sort/">define sorting</a></li>
<li>msg.limit (number) - <a href="https://docs.mongodb.com/drivers/node/current/fundamentals/crud/read-operations/limit/">limit number of results</a></li>
<li>msg.skip (number) - <a href="https://docs.mongodb.com/drivers/node/current/fundamentals/crud/read-operations/skip/">skip results</a></li>
</ul>
</p>
</script>
18 changes: 14 additions & 4 deletions find.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ module.exports = function (RED) {
var node = this;

node.on('input', function (msg) {
var db = RED.nodes.getNode(config.db).getDB();
let db = RED.nodes.getNode(config.db).getDB();

db.collection(config.collection).find(msg.payload).toArray(function (err, docs) {
msg.payload = docs;
node.send(msg);
let cursor = db.collection(config.collection).find(msg.payload);
if (msg.sort) {
cursor.sort(msg.sort);
}
if (msg.limit) {
cursor.limit(msg.limit);
}
if (msg.skip) {
cursor.skip(msg.skip);
}
cursor.toArray(function (err, docs) {
msg.payload = docs;
node.send(msg);
});
});
}
Expand Down
68 changes: 40 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
{
"name": "node-red-contrib-tingodb",
"version": "1.0.4",
"description": "TingoDB nodes",
"keywords": [ "node-red", "tingo", "tingodb", "database", "db" ],
"node-red": {
"nodes": {
"tingodb": "tingodb.js",
"tingodb-find": "find.js",
"tingodb-insert": "insert.js",
"tingodb-remove": "remove.js",
"tingodb-update": "update.js"
}
},
"bugs": {
"url": "https://github.com/eazel7/tingo-red/issues"
},
"name": "node-red-contrib-tingodb",
"version": "1.1.0",
"description": "TingoDB nodes",
"keywords": [
"node-red",
"tingo",
"tingodb",
"database",
"db"
],
"node-red": {
"nodes": {
"tingodb": "tingodb.js",
"tingodb-find": "find.js",
"tingodb-insert": "insert.js",
"tingodb-remove": "remove.js",
"tingodb-update": "update.js"
}
},
"bugs": {
"url": "https://github.com/eazel7/tingo-red/issues"
},
"repository": {
"type" : "git",
"url" : "https://github.com/eazel7/tingo-red.git"
},
"scripts": {},
"author": {
"name": "Diego Pérez",
"email": "diego@cerovueltas.com.ar"
},
"license": "ISC",
"dependencies": {
"tingodb": "^0.5.1"
}
"type": "git",
"url": "https://github.com/eazel7/tingo-red.git"
},
"scripts": {},
"author": {
"name": "Diego Pérez",
"email": "diego@cerovueltas.com.ar"
},
"contributors": [
{
"name": "Oliver Charlet",
"email": "oliver.charlet@clarities.de"
}
],
"license": "ISC",
"dependencies": {
"tingodb": "^0.5.1"
}
}