diff --git a/77-cloudant-cf.html b/77-cloudant-cf.html index ae0c58d..72787fa 100644 --- a/77-cloudant-cf.html +++ b/77-cloudant-cf.html @@ -115,6 +115,7 @@ @@ -122,7 +123,7 @@ / - +
@@ -214,7 +215,7 @@ searchBySelect.change(function() { var searchBy = searchBySelect.val(); - if (searchBy === "_idx_") { + if (searchBy === "_idx_" || searchBy === "_view_") { node._def.defaults.design.required = true; node._def.defaults.index.required = true; searchForm.show(); diff --git a/77-cloudant-cf.js b/77-cloudant-cf.js index da9e816..48d3c77 100644 --- a/77-cloudant-cf.js +++ b/77-cloudant-cf.js @@ -99,8 +99,8 @@ module.exports = function(RED) { } node.on("input", function(msg) { - if (err) { - return node.error(err.description, err); + if (err) { + return node.error(err.description, err); } delete msg._msgid; @@ -271,6 +271,11 @@ module.exports = function(RED) { sendDocumentOnPayload(err, body, msg); }); } + else if (node.search === "_view_") { + db.view(node.design, node.index, options, function(err, body) { + sendDocumentOnPayload(err, body, msg); + }); + } else if (node.search === "_all_") { options.include_docs = options.include_docs || true; @@ -313,9 +318,14 @@ module.exports = function(RED) { if ("rows" in body) { msg.payload = body.rows. map(function(el) { - if (el.doc._id.indexOf("_design/") < 0) { - return el.doc; + if (el.doc) { + if (el.doc._id.indexOf("_design/") < 0) { + return el.doc; + } + } else { + return el; } + }). filter(function(el) { return el !== null && el !== undefined; diff --git a/README.md b/README.md index 790b9fb..f7fbd84 100644 --- a/README.md +++ b/README.md @@ -23,15 +23,21 @@ in JSON format, it will be transformed before being stored. For **update** and **delete**, you must pass the `_id` and the `_rev`as part of the input `msg` object. -To **search** for a document you have two options: get a document directly by -its `_id` or use an existing [search index](https://cloudant.com/for-developers/search/) -from the database. For both cases, the query should be passed in the -`msg.payload` input object as a string. +To **search** for a document you have three options: +* get a document directly by its `_id` +* use an existing [search index](https://cloudant.com/for-developers/search/) +from the database +* use an existing [view](https://console.bluemix.net/docs/services/Cloudant/api/using_views.html#using-views) When getting documents by id, the `payload` will be the desired `_id` value. + For `search indexes`, the query should follow the format `indexName:value`. +For `views`, `payload` should be set be set to an object containing key/value pairs +as defined in the Query string section in the [Cloudant documentation](https://console.bluemix.net/docs/services/Cloudant/api/using_views.html#using-views) + Authors ------- * Luiz Gustavo Ferraz Aoqui - [laoqui@ca.ibm.com](mailto:laoqui@ca.ibm.com) * Túlio Pascoal +* Adam Hammond diff --git a/package.json b/package.json index 69b3440..096f6da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-node-cf-cloudant", - "version": "0.2.17", + "version": "0.3.1", "description": "A Node-RED node to access Cloudant and couchdb databases", "dependencies": { "cfenv": "1.0.0", @@ -32,6 +32,9 @@ }, { "name": "Igor Leão" + }, + { + "name": "Adam Hammond" } ], "maintainers": [