Database change notification insert or update

36 views
Skip to first unread message

Jean Regisser

unread,
Dec 16, 2014, 6:08:58 AM12/16/14
to mobile-c...@googlegroups.com
Hi,

I'm trying to see if there's a way to know if a document was inserted in the DB or just updated with a new revision.

Looking at the kCBLDatabaseChangeNotification on the iOS implementation, I see that there's an array of CBLDatabaseChange
that's passed with the notification. However I don't yet see a way to know if the change was an insertion or just an update.

Is it possible to know that?

Thanks!

Jens Alfke

unread,
Dec 16, 2014, 12:35:24 PM12/16/14
to mobile-c...@googlegroups.com

On Dec 16, 2014, at 3:08 AM, Jean Regisser <jean.r...@gmail.com> wrote:

Looking at the kCBLDatabaseChangeNotification on the iOS implementation, I see that there's an array of CBLDatabaseChange
that's passed with the notification. However I don't yet see a way to know if the change was an insertion or just an update.

It depends on what exactly you mean by "insertion". Do you mean a first-generation document, or a document that's new to the local database?

You can detect a new (first-generation) document by looking at the revision history, checking whether doc.currentRevision.parentRevision == nil. Or a cheaper way to do the same thing is to see whether the revision ID begins with "1-" which means it's first-generation.

But the replicator will add documents to the local database that aren't first-generation. You can check the `source` property of the CBLDatabaseChange to see whether this revision was added by the replicator, but there isn't anything that tells you whether the document existed locally beforehand.

—Jens
Reply all
Reply to author
Forward
0 new messages