On Jan 20, 2014, at 6:31 AM, paul Orsillo <[email protected]> wrote:

>  CBLUnsavedRevision *newRev = [tgtDoc newRevision];
>  [propSet setValue:newRev forKey:@"_rev"];

This doesn't make sense. The value of a "_rev" property is a string, not a 
CBLUnsavedRevision object. (Remember, a document's properties are JSON, so the 
only types you can use are numbers, strings, NSNull, arrays and dictionaries.)

If you want to completely replace a document's properties, you can do it like 
this:

CBLUnsavedRevision *newRev = [tgtDoc newRevision];
newRev.userProperties = propSet;
ok = [newRev save: &error];

or a slightly better variation:

[tgtDoc update: ^(CBLUnsavedRevision* newRev) {
        newRev.userProperties = propSet;
} error: &error];

The reason the second form is better is that it handles the race condition 
where some other thread (such as the replicator) updates the document in 
between the newRevision and the save, which will cause a conflict (409). The 
update:error: method handles this internally and starts over again.

—Jens

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/9EC05C5A-ED57-4CD7-83DA-AC110E52CB07%40couchbase.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to