What does the changes API actually do? does it list the last revision of each document + deleted documents?
or to put it this way:
开发者_开发知识库Can the change notifications feature of couchdb be used to list all the documents that match a query?
For example, if I have the filter function:
search = function(doc,req)
{
return (doc.min && doc.max && doc.min < req.query.q && doc.max > req.query.q)
}
will I get all the documents that match doc.min < somevalue < doc.max here?
http :// server / database / _changes ? filter=doctype/search & q=somevalue
For my test database it appears to be so, but what if I have a large database?
Every write to the database is given what is known as a seqnum. (or sequence number) A log of those writes is stored with the document _id, _rev, amongst other information about the write. (See this section of the CouchDB book online.) A newly-created document gets the next seqnum (old seqnum + 1). A document update, on the other hand, also appends a new seqnum but also removes the document's old one from from the log. If you list all documents ordered by seqnum, you get a timeline of the evolution of the data.
Calling the _changes API retrieves that list. And since every revision is saved in it's entirity (not just a delta of changes) then you can reconstruct everything that has changed in that database since a particular seqnum.
Running a compaction removes old document revisions, but does not affect the seqnum or _changes data. This is because _changes shows only the latest (live) revisions of the documents.
加载中,请稍侯......
精彩评论