janmonschke / backbone-couchdb

A couchdb connector for backbone with support for real time changes.

Home Page:http://janmonschke.com/projects/backbone-couchdb.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change feed not working with CouchDb 1.0.2

ahamid opened this issue · comments

Hi there, I recently upgraded backbone and backbone-couchdb in my CouchApp and started noticing a problem with the changes feed.

Backbone-couchdb appears to be requesting a URL like this:

http://localhost:6984/dbname/_changes?heartbeat=10000&include_docs=true&collection=models&filter=dbname%2Fby_collection&feed=longpoll&since=1

and always gets: "404 Object not found" with the body: {"error":"not_found","reason":"missing json key: filters"}

After some discussion on IRC my guess is that Backbone-couchdb is using more recently CouchDb functionality to "filter" the change stream via a view/map function.

"<rnewson> it probably assumes couch 1.1 where you can point at a map function."

My guess is that this is getting set up per-model, and previously it was a global feed (hence, no filtering).

Is this correct, and if so, is there any way to avoid this filtering (use a global feed) or do I just need to upgrade CouchDb, or downgrade Backbone-couchdb?

Thanks for any feedback!

I seem to be able to make progress by defining an explicity by_collection filter in the design doc:

function(doc, req) {
  if (doc.collection) {
    emit(doc.collection, doc);
  }
}

Sure, there needs to be a filter function with that name.
If you're using the couchapp tool, you could easily copy one of the examples and add your own code.
Do you still get the 404 errors?

Hi Jan, I think adding the explicit filter function above cured the problem (I did: 'couchapp generate by_collection'). Thanks!
Closing and leaving for posterity.

I think the filter function should be something like:

function(doc, req) {
  if (doc.QUERY_VAR && doc.QUERY_VAR==req.query.QUERY_VAR)
    return true;
  else 
    return false;
}

At least, that is what worked for me.

Ahh, I did not see that. Thank you. Do you think it would it be worth it to put that function in the main docs?

Maybe I should add it to the overall README of the project.