Last active
August 29, 2015 14:03
-
-
Save jeffcogswell/1c2f06f5dcd152c055b6 to your computer and use it in GitHub Desktop.
Cloudant Index Creation using node and nano.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 creates an index. | |
To try this, first replicate the database as per | |
instructions here: | |
http://docs.cloudant.com/guides/cloudant-query.html | |
Then install nano like so: | |
npn install nano | |
And then run this file (after replacing USERNAME | |
and PASSWORD with your own): | |
node create_C_index.js | |
Then here's some sample code for querying: | |
https://gist.github.com/jeffcogswell/de7e552671780011b9f4 | |
*/ | |
var nano = require('nano')({ url: 'https://[USERNAME]:[PASSWORD]@[USERNAME].cloudant.com' }); | |
var query = { | |
"index": { | |
"fields": ["Person_name"] | |
} | |
} | |
var opts = { | |
path: '_index', | |
db: 'movies-demo', | |
method: 'post', | |
body: query | |
}; | |
nano.request(opts, function(err, result) { | |
// err should be null | |
console.log(err); | |
// result should be { result: 'created' } | |
console.log(result); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment