Skip to content

Instantly share code, notes, and snippets.

@jeffcogswell
Last active August 29, 2015 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffcogswell/de7e552671780011b9f4 to your computer and use it in GitHub Desktop.
Save jeffcogswell/de7e552671780011b9f4 to your computer and use it in GitHub Desktop.
/*
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