I'm currently using nano to interact with couchdb in node.js. This is how I insert a document:
var user = {
'name': 'Neon',
'age': 12,
'type': 'user'
};
db.insert(user, function(err, body){
if(err === null){
response = {
'type': 'success',
'message': 'User created'
};
}
res.send(response);
});
And then I created a view that will return only the documents whose type is 'user':
db.insert(
{ "views":
{ "by_user":
{ "map": function(doc) {
if(doc.type == 'user'){
emit([doc.name], doc._id);
}
} }
}
}, '_design/people', function (error, response) {
console.log("yay");
});
But when I use the view to further trim down the results:
db.search('people', 'by_user', {'age': 16}, function(err, body) {
if (!err) {
res.send(body);
}else{
console.log('eror occured');
console.log(err);
}
res.send(response);
});
I'm getting this as a response:
{ [Error: missing handler: _search]
name: 'Error',
error: 'not_found',
reason: 'missing handler: _search',
scope: 'couch',
statusCode: 404,
request:
{ method: 'GET',
headers:
{ 'content-type': 'application/json',
accept: 'application/json' },
uri: 'http://root:nitoryolai@localhost:5984/chatapp/_design/people/_search/by_user',
qs: { name: 'wern' } },
headers:
{ date: 'Fri, 27 Mar 2015 07:50:06 GMT',
'content-type': 'application/json',
'cache-control': 'must-revalidate',
statusCode: 404,
uri: 'http://root:mypassword@localhost:5984/my_db/_design/people/_search/by_user' },
errid: 'non_200',
description: 'couch returned 404' }
Any ideas what I'm missing here? Thanks in advance.