2

I am new to using Couchbase but based on the documentation it seems that Couchbase is a good fit for my use case to store user data as documents. I have created a view on Couchbase which I am able to run and see the results in the dashboard. However when I run the view query from my node.js application, the server responds with an empty result.

var cluster = new couchbase.Cluster("couchbase://localhost");
var bucket = cluster.openBucket("default");
var bmanager = bucket.manager();
var viewQuery = couchbase.ViewQuery;
var query = viewQuery.from('todoNew', 'ToDoNew'); //design doc name, view name

app.get("/todo/:New", function(req, res){ 
bucket.query(query, function(err, results) {
            for(i in results)
            console.log(results[i]);
            }); 
})

$ curl http://localhost:3000/todo/New % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- 0:02:00 --:--:-- 0 curl: (52) Empty reply from server

Here is an example json doc on Couchbase

{
"fromUserName": "Earl",
"toUserName": "Fred",
"description": "my description",
"id": 11,
"title": "Run marathon",
"status": "New"
}

And here is the view map function

function (doc, meta) {
 if(doc.status == 'New') {
 emit(meta.id, doc.toUserName, doc.title, doc.description);
 }
}

The above view function when executed from the couchbase dashboard returns docs like this

enter image description here

Any suggestion is much appreciated.

Roi Katz
  • 575
  • 4
  • 14
user1384205
  • 1,231
  • 3
  • 20
  • 39

0 Answers0