On Thu, Jun 23, 2011 at 3:26 AM, Randall Leeds <[email protected]> wrote:
> Why do you need to know the difference and what defines "created" for you?
> Would a document that replicated from elsewhere count as "created" or
> only if it's the first revision?
> What if revision 2-* replicates in?
_changes is a false prophet.
The best bang-for-buck with the _changes feed is cache invalidation: A
change is a *hint* that you might want to check something out, but it
is (IMHO) not generally the primary trigger to execute some code.
I have found success pushing intelligence to the client, combined with
a validate_doc_update() function that confirms that intelligence.
In your case: Require all new docs to have a field "is_new: true".
That is very easy to confirm in the validator:
if(oldDoc && newDoc.is_new)
throw {forbidden: "Updates must REMOVE is_new"};
if(!oldDoc && !newDoc.is_new)
throw {forbidden: "Creates must SET is_new"}
It is also very easy to see in the _changes feed
if(change.doc.is_new)
do_stuff_with_new_doc(change.doc);
This workflow is compatible with replication, since the peers will
(presumably) enforce the same policy. (If you are allowing them to
update your db, presumably you trust them.)
--
Iris Couch