Hi,
        http://guide.couchdb.org/draft/notifications.html#filters

I think you'd want to query _changes with a filter to check that the doc.name is the same as that from the query string, slightly modifying the example from the book:

function(doc, req)
{
  if(doc.id == req.query.id && doc.name != req.query.name) {
    return true;
  }

  return false;
}

You'd then query http://localhost:5984/helloworld/_changes with something like _changes?filter=myapp/myfilter&id=app1&name=Hello which would return all changes for documents with id=app1 where the name differs from what you set.

I don't think you can filter what the change is reliably, though. For instance the filter above would miss someone changing the name back to "Hello" unless you change the query string, which means your application will need to hold that piece of state information. You can easily see all changes for a given document, and then further filter later on, though, maybe that's sufficient?
Cheers
Simon

On 20 Oct 2010, at 13:31, chirayu shah wrote:

Hi,

The output that we get with the _changes database API tells us which
document was changed and its revision information.
Is there a way to get the notification when a particular key of a document
is changed?

Basically is there a way to listen to a specific key of a document of a
database?

For eg: Suppose I have a database as "helloworld", which has 2 documents
"app1" and "app2" whose contents are as follows:

app1 :

{
  "_id": "app1",
  "_rev": "2-c1765690ce0ba5c4d51bd6e06f6d63e1",
  "name": "Hello",
  "title": "World"
}


app2:

{
  "_id": "1",
  "_rev": "2-95ca949e944d55bdb0dc79b8d8223f05",
  "a": 2,
  "b": 4
}


Now I want to listen to the key "name" of the document "app1" for changes. So I should receive the notification when the value of "name" changes and
not if the value of "title" changes.

Is there a way to do this in CouchDB? If yes, then how?
Any help would be much appreciated.

Thanks,
Chirayu.

Reply via email to