@andreas.paetzold (Andreas Paetzold) posted a new topic, subject "Document deletion does not get synced to other device". It read:

   I have two devices (A & B), both using the Couchbase username.  
    If I delete a document on Device A via Document.delete() Method, the deletion does not get synced to device B, even if the deletion was properly synced to Couchbase Server.
    
    Only if I use the alternative way, the deletion gets synced :
    
    var doc = database.GetDocument(myDocId);  
    doc.Update((UnsavedRevision newRevision) =>  
    {  
    newRevision.IsDeletion = true;  
    return true;  
    });
    
    The alternative way is only necessary when I need to preserve fields, according to Documentation.
    
    Update:  
    SyncGateway produces the following output when invoking sync on Device B
    
    2016-03-29T14:33:43.320+02:00 HTTP: #508: GET /hamster/  
    2016-03-29T14:33:43.320+02:00 HTTP: #508: \--> 401 Login required (0.5 ms)  
    2016-03-29T14:33:43.327+02:00 HTTP: #509: GET /hamster/  
    2016-03-29T14:33:43.327+02:00 HTTP: #509: \--> 401 Login required (0.4 ms)  
    2016-03-29T14:33:43.400+02:00 HTTP: #510: PUT /hamster/_local/424bf94e12e3842ef2be5b89044a7fb55b1c5fbf (as USER)  
    2016-03-29T14:33:43.402+02:00 HTTP: #510: \--> 409 Document update conflict (2.6 ms)  
    2016-03-29T14:33:43.408+02:00 HTTP: #511: GET /hamster/_local/218bc19b567937692dd28753841527951b8f54e0 (as USER)  
    2016-03-29T14:33:43.496+02:00 HTTP: #512: POST /hamster/_changes (as USER)  
    2016-03-29T14:33:43.499+02:00 Changes+: Int sequence multi changes feed…  
    2016-03-29T14:33:43.499+02:00 Changes: MultiChangesFeed({USER}, {Since:78 Limit:0 Conflicts:true IncludeDocs:false Wait:false Continuous:false Terminator:0xc820b2fc80 HeartbeatMs:300000 TimeoutMs:300000 ActiveOnly:false}) … (to USER)  
    2016-03-29T14:33:43.500+02:00 Changes+: MultiChangesFeed: channels expand to channels.TimedSet{“USER”:channels.VbSequence{VbNo:(*uint16)(nil), Sequence:0x2}} … (to USER)  
    2016-03-29T14:33:43.500+02:00 Changes+: Sending seq:79 from channel USER  
    2016-03-29T14:33:43.500+02:00 Changes+: MultiChangesFeed sending &{Seq:79 ID:-JbyqMJi5CUK1MDX1NrLq-A Deleted:true Removed:{USER} Doc:map[] Changes:[map[rev:13-9ca068d75811871db795fbbde650dcf6] map[rev:11-0324b2fdbb5efa9e44c1dfe87eedf837]] Err: allRemoved:true branched:true} (to USER)  
    2016-03-29T14:33:43.501+02:00 Changes: MultiChangesFeed done (to USER)  
    2016-03-29T14:33:43.604+02:00 HTTP: #513: PUT /hamster/_local/218bc19b567937692dd28753841527951b8f54e0 (as USER)

So @borrrden (Jim Borden) replied

    Perhaps your sync function is basing its logic off of properties that are not on the document when the deletion comes in. In that case, the user will be removed from the channel and further updates will not be replicated to the user.

So @andreas.paetzold (Andreas Paetzold) replied

    I don't understand what you mean exactly.
    
    My sync function is the following:
    [code] 
        function(doc, oldDoc)
                {
                        if(oldDoc != null)
                        {
                                requireUser(oldDoc.Owner);
                        }
                        channel(doc.channels);
        
                }`,
        
    [/code]
    
    Could you explain in more detail what you mean?

So @borrrden (Jim Borden) replied

    Well, doc.channels will be blank on a deletion if you delete it the normal way (not the “update” way) because it removes all properties. This would cause it to not be added to the channels it was previously added to, which is the same as removing them. This removal means that the other user potentially does not have access to the document anymore and so the last known revision of the document in the context of the other user will be the revision just before the deletion.

After which, @andreas.paetzold (Andreas Paetzold) added

    Ah okay, now I get it. Does it mean that the delete() method is not suitable for my purpose, or is there any change to my sync function necessary?

To which @borrrden (Jim Borden) replied

    Either way would be an acceptable solution. You could check if the document is deleted and sync the change to the channels on the oldDoc instead for a sync-time solution.

@andreas.paetzold (Andreas Paetzold) replied

    Thank you very much! Got it now working. If someone else facing the same issue, I solved it this way:
    [code] 
        function(doc, oldDoc)
        {
                        if (doc._deleted)
                        {
                                channel(oldDoc.channels);
                                // Skip other validation because a deletion has no other properties:
                                return;
                        }
                        if(oldDoc != null)
                        {
                                requireUser(oldDoc.Owner);
                        }
        
                        channel(doc.channels);
        }
    [/code]


{'source': 'discourse', 'url': 'https://forums.couchbase.com/t/document-deletion-does-not-get-synced-to-other-device/7580', 'title': 'Document deletion does not get synced to other device', 'views': 1423, 'has_accepted_answer': True, 'word_count': 644, 'like_count': 0, 'reply_count': 1, 'participant_count': 2, 'posts': 7, 'tags': '', 'author': '@andreas.paetzold (Andreas Paetzold)', 'participants': '@andreas.paetzold (Andreas Paetzold), @borrrden (Jim Borden)', 'image_url': [None], 'created_at': '2016-03-29T12:29:09.341Z', 'last_posted_at': '2016-03-30T08:45:34.278Z'}