Skip to content

Commit fbe2f57

Browse files
committed
* accept cloudant search index params in payload
* send cloudant results in message object
1 parent cc3bc65 commit fbe2f57

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

77-cloudant-cf.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ module.exports = function(RED) {
231231
else {
232232
node.on("input", function(msg) {
233233
var db = cloudant.use(node.database);
234+
var options = (typeof msg.payload === "object") ? msg.payload : {};
234235

235236
if (node.search === "_id_") {
236237
var id = getDocumentId(msg.payload);
@@ -241,8 +242,10 @@ module.exports = function(RED) {
241242
});
242243
}
243244
else if (node.search === "_idx_") {
244-
var query = { q: formatSearchQuery(msg.payload) };
245-
db.search(node.design, node.index, query, function(err, body) {
245+
options.q = options.q || formatSearchQuery(msg.payload);
246+
options.limit = options.limit || 200;
247+
248+
db.search(node.design, node.index, options, function(err, body) {
246249
sendDocumentOnPayload(err, body, msg);
247250
});
248251
}
@@ -277,7 +280,8 @@ module.exports = function(RED) {
277280

278281
function sendDocumentOnPayload(err, body, msg) {
279282
if (!err) {
280-
msg.payload = body;
283+
msg.payload = body.rows;
284+
msg.cloudant = body;
281285
} else {
282286
msg.payload = null;
283287

0 commit comments

Comments
 (0)