public
Created

Create CouchBase view with node.js

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
var memcache = require('memcache');
var client = new memcache.Client()
client.host = 'localhost'
client.port = 11211;
client.on('error', function(e){
console.log("couchbase error");
console.log(e);
});
 
var users = {
"_id": "_design/dev_users",
"language": "javascript",
"views": {
"usernames": {
"map": "function (doc) {\n if(doc.jsonType == \"user\") {\n emit(doc.username, doc);\n }\n}"
},
"emails": {
"map": "function (doc) {\n if(doc.jsonType == \"user\") {\n emit(doc.email, doc);\n }\n}"
}
},
"spatial": {}
}
 
client.connect();
 
client.set('_design/dev_users', JSON.stringify(users), function(error, result) {
console.log(error, result);
client.close();
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.