Hello Couchbase community. Ive been developing a project for sometime and for some reason I cant seem to find the ideal solution for what I am trying to achieve.
I have an outside source making changes to a Couchbase document and I am trying to monitor what type of change was made in order to take the appropriate steps. How can I either get the document channel or document name from inside the change listener?
This is the snip-it of code I am referring to.
Replication mPullReplication = mDatabase.createPullReplication(url);
mPullReplication.setContinuous(true);
mPullReplication.addChangeListener(new Replication.ChangeListener() {
@Override
public void changed(Replication.ChangeEvent changeEvent) {
//I want to check the document's channel, or name here.
}
});
Any ideas would be greatly appreciated!
Maybe I am looking in the wrong place. Where would be the best place be to get the document id or channels as soon as a change is made?
Hello @Peachk33n,
To monitor the changes for document notifications, you can be notified when new revisions are added to a document, when a document is deleted or when a documented is conflicted with another entry:
Document doc = database.createDocument(); doc.addChangeListener(new Document.ChangeListener() { @Override public void changed(Document.ChangeEvent event) { DocumentChange docChange = event.getChange(); String msg = "New revision added: %s. Conflict: %s"; msg = String.format(msg, docChange.getAddedRevision(), docChange.isConflict()); Log.d(TAG, msg); documentChanged.countDown(); } }); doc.createRevision().save();
To get the documentID you would call the getId()
method on the particular revision of the document.
You may set up a key from within your document that has the ‘channel’ parameter-value and then reference that particular key when you have your document of interest.
Thanks,
William