Here’s simpler code:
Create document:
view.findViewById(R.id.create).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Map<String, Object> properties = new HashMap<>();
properties.put("title", "My title");
properties.put("channels", "b91a8c08-5e1e-4d1b-a163-9f2b2a7ee0a7");
Document document = CouchbaseUtilv6.getInstance(getActivity()).getDatabase().getDocument("ID-2");
try {
document.putProperties(properties);
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
}
It’s created, synced and this is in CB Server console:
{
"_sync": {
"rev": "1-ef11eb88fd17703d25ddb277a8684cae",
"sequence": 345,
"recent_sequences": [
345
],
"history": {
"revs": [
"1-ef11eb88fd17703d25ddb277a8684cae"
],
"parents": [
-1
],
"channels": [
[
"b91a8c08-5e1e-4d1b-a163-9f2b2a7ee0a7"
]
]
},
"channels": {
"b91a8c08-5e1e-4d1b-a163-9f2b2a7ee0a7": null
},
"time_saved": "2017-12-21T11:35:53.871041716Z"
},
"channels": "b91a8c08-5e1e-4d1b-a163-9f2b2a7ee0a7",
"title": "My title"
}
Code to delete document:
view.findViewById(R.id.delete).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Document document = CouchbaseUtilv6.getInstance(getActivity()).getDatabase().getDocument("ID-2");
document.delete();
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
}
});
It’s synced and in CB Server console:
{
"_deleted": true,
"_sync": {
"rev": "2-6a2118f4a8bfc690ab62f79c295b8875",
"flags": 1,
"sequence": 346,
"recent_sequences": [
345,
346
],
"history": {
"revs": [
"1-ef11eb88fd17703d25ddb277a8684cae",
"2-6a2118f4a8bfc690ab62f79c295b8875"
],
"parents": [
-1,
0
],
"deleted": [
1
],
"channels": [
[
"b91a8c08-5e1e-4d1b-a163-9f2b2a7ee0a7"
],
null
]
},
"channels": {
"b91a8c08-5e1e-4d1b-a163-9f2b2a7ee0a7": {
"seq": 346,
"rev": "2-6a2118f4a8bfc690ab62f79c295b8875",
"del": true
}
},
"time_saved": "2017-12-21T11:36:23.8573285Z"
}
}
When I create the document again, then this message is in Android Studio logs:
W/Sync: {error=forbidden, id=ID-2, reason=missing channel access, status=403}: _bulk_docs got an error: com.couchbase.lite.replicator.PusherInternal$6@53b59c9
Sync function is as above.