Question about views and filters
dvberkel opened this issue · comments
I am working on a project which uses backbone-couchdb.
I have trouble getting view
and filter
to work together. It could be the case that it depends on my understand of CouchDB, the backbone-couchdb connector or both.
Context
I am saving notes. An example can be found below. (Id's and revision are striped for brevity.)
{ "key":"notes","value":{"content":"Example","active":true,"edit":false,"x":10,"y":10, "user":"dvb","collection":"notes"}}
With a view active_notes
:
function(doc) {
if (doc.collection == 'notes' && doc.active) {
emit(doc.collection, doc);
}
}
and a filter per_user
:
function(doc, req) {
if (doc.collection == 'notes' && doc.user == req.userCtx.name) {
return true;
}
return false;
}
I would expect the following Backbone.Collection
to only retrieve the "active" documents from the logged in user.
Backbone.Collection.extend({
url : "/notes",
db : {
view : "active_notes",
filter : Backbone.couch_connector.config.ddoc_name + "/per_user"
},
model : NoteModel
});
Instead all "active" documents are retrieved.
Care to shed some light on the interplay between views and filters?
I have reread couchdb documentation and my expectations about views and filters were wrong.
I am working in the following direction. Create a view which emits an array key and use view parameters