Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
nano doesn't yet have support for Cloudant's new index feature,
but you can still do it using nano's request function.
This code queries an index.
To try this, first replicate the database as per
instructions here and make sure you created an index.
(Also check out my node.js code to create the index
here:https://gist.github.com/jeffcogswell/1c2f06f5dcd152c055b6)
Then install nano like so:
npn install nano
And then run this file (after replacing USERNAME
and PASSWORD with your own):
node query_C_index.js
*/
var nano = require('nano')({ url: 'https://[USERNAME]:[PASSWORD]@[USERNAME].cloudant.com' });
var query = { "selector": { "Person_name": "Zoe Saldana" } };
var opts = {
path: '_find',
db: 'movies-demo',
method: 'post',
body: query
};
nano.request(opts, function(err, result) {
// err should be null
console.log(err);
// result should be a list containing info about the movie Avatar
console.log(result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment