I am building a simple couchapp CRUD application. When I fetch a view, I get a 304 response from CouchDB. In futon, the same view returns documents.
Below is the snippet where I am querying the view and appending the returned items to a div. In the javascript console, I get an error saying “Can not read property _id of null”
db = $.couch.db("itemly");
function updateItems(){
$("#all").empty();
db.view("itemly/byitemname",{ success: function(data){
for (i in data.rows){
$("#all").append('<div id="' + data.rows[i].value._id + '" class ="itemrow"><span>'+data.rows[i].value.name + "</span><span>"+data.rows[i].value.price + "</span><span>"+data.rows[i].value.category + "</span><span>"+'<a href="#" id="'+ data.rows[i].value._id + '" class = "edit"> Edit Item </a>' +"</span><span>"+'<a href="#" id="'+ data.rows[i].value._id + '" class = "remove"> Remove Item </a>' +"</span></div>");
}
}
});
}
}
I finally figured out the issue. I used
to generate my view. It created a “map.js” as well as a “Reduce.js” file. I edited the map.js file according my requirement but the empty reduce.js file resulted in couchdb returning null when I fetched the view.
Note that in futon, the view “byitemname” worked properly because in futon, you have to explicitly run the reduce.js but while fetching from an app this happens automatically.