Multiple (and variable) input Cloudant query

332 views
Skip to first unread message

Pablo Vicente García

unread,
Jun 20, 2017, 4:08:09 AM6/20/17
to Node-RED
Hello!

I am working on an IoT project that includes several Cloudant databases. Related to one of them, there is a dashboard which has a dropdown I want to use to create a query and retrieve database data.

The Node Red flow is the following:

This is how the dashboard looks like:



What I am trying to do is that you could be able to create the query with any of the available parameters, not just with all of them. I have read the Cloudant documentation and I think the function node should have something like this:

msg.payload = 
{
    "selector": {        
        "nombre":msg.payload.nombre;
        "apellido1":msg.payload.apellido1,
        "apellido2":msg.payload.apellido2,
        "nacimiento":msg.payload.nacimiento,
        "alergias":msg.payload.alergias,
        "fechaIngreso":msg.payload.fechaIngreso,
        "afeccion":msg.payload.afeccion,
        "fechaAlta":msg.payload.fechaAlta
  }
};

return msg;

Does anyone have an idea about this?

Thank you in advance.

P.S.: I am working on IBM Bluemix.

Abhay Tiwari

unread,
Sep 25, 2017, 12:10:53 PM9/25/17
to Node-RED
Hi Pablo,

I assume you have created search index to retrieve data from cloudant database. This gives you flexibility to fetch records based on index which you create.
For example: if you happen to create a search index named - <my_index>, you need to pass payload to cloudant search node as - msg.payload="<my_index>:"+msg.payload; Note - you need to pass your form data as argument (highlighted one).
While creating index on database you are allowed to edit "search index function",  you can write your search logic here by editing the function.


Sample search index function -

function(doc) {
    index("default", doc._id);
    if (doc.min_length) {
        index("min_length", doc.min_length, {"store": true});
    }
    if (doc.diet) {
        index("diet", doc.diet, {"store": true});
    }
    if (doc.latin_name) {
        index("latin_name", doc.latin_name, {"store": true});
    }
    if (doc.class) {
        index("class", doc.class, {"store": true});
    }
}
Reply all
Reply to author
Forward
0 new messages