Replication Pull Ignores Deleted Documents
yourteam opened this issue · comments
Deletions on the remote server are not replicated during a pull request.
Reproduce: Execute a replication pull from a remote server. Delete one or more documents on the remote server. Execute another pull from the remote server.
Expected: Documents deleted on the remote server are also deleted on the local server.
Observed: Documents are not deleted on the local server.
Note: I think the sequence number may not be updating correctly to recognize document deletions.
CouchDbConnector tempConnect = Global.getLocalTouchConnector(mContext);
TDDatabase db = Global.getLocalTouchDatabase(mContext);
TDReplicator replicator = null;
try
{
replicator = db.getReplicator(new URL("https://" + mUsername + ":" + mPassword + "@" + Global.YOURTEAM_DB_PATH), false, false);
}
catch (MalformedURLException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
long updateSeq = tempConnect.getDbInfo().getUpdateSeq();
// Get changes since our previous dbsequncenumber.
ChangesCommand cmd = new ChangesCommand.Builder().since(updateSeq).includeDocs(true).build();
replicator.setFilterName("rep_filters/doc_by_userid");
replicator.start();
while (replicator.isRunning())
{
Log.i("hi", "Waiting for replicator to finish");
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
List<DocumentChange> changes = tempConnect.changes(cmd);
for (DocumentChange change : changes)
{
String docId = change.getId();
if (change.isDeleted())
{
tempConnect.delete(docId, change.getRevision());
}
else
{
...
}
}
in TDDatabase :
in the method appendDictToJSON :
if(jsonLength == 2) { // Original JSON was empty
return extraJSON;
}
have to by replace by
if(jsonLength == 0) { // Original JSON was empty
return extraJSON;
}
This is likely caused by a filter function which doesn't take into account deleted documents. (this is so common there is a FAQ about it)
Closing ticket, re-open if that's not the reason, and provide a filter function you are using.