oberon
February 13, 2014, 7:48pm
1
I’m trying to update documents: REST API(Http Request) --> Sync Gateway --> Couchbase Server 2.0, like http://docs.couchbase.com/couchbase-lite/cbl-api/#put-dbdoc .
I have tried:
PUT http://[IPServer]:4985/sync_gateway/test_doc?rev=1-4101356e9c47d15d4f8f7390d05dbbcf
Content-Type: application/json
{
“description”: “Doc Updated”
}
and also:
PUT http://[IPServer]:4985/sync_gateway/test_doc
Content-Type: application/json
If-Match: 1-4101356e9c47d15d4f8f7390d05dbbcf
{
“description”: “Doc Updated”
}
I’ve made sure that “ID” and “rev” are correct, but it doesn’t work for me. It says:
“error”:“conflict” , “reason”:“Document exists”
.
How can I add new data to documents?
Thanks.
jliu
February 13, 2014, 9:31pm
2
Hmmm. Can you copy/paste the full PUT string for us?
traun
February 13, 2014, 10:00pm
3
Assuming you are using the native java API for updating documents with Couchbase Lite, this is an example of how to do this:
QueryRow row = (QueryRow) adapterView.getItemAtPosition(position);
Document document = row.getDocument();
Map<String, Object> newProperties = new HashMap<String, Object>(document.getProperties());
boolean checked = ((Boolean) newProperties.get("check")).booleanValue();
newProperties.put("check", !checked);
try {
document.putProperties(newProperties);
grocerySyncArrayAdapter.notifyDataSetChanged();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Error updating database, see logs for details", Toast.LENGTH_LONG).show();
Log.e(TAG, "Error updating database", e);
}
}
/**
* Handle long-click on item in list
If you are using Ektorp or the REST api, it would be a different way and I can provide docs for that too.
Which version of Couchbase Lite are you using? beta1, beta2 or the current master branch on github?
oberon
February 14, 2014, 8:41am
4
Sorry, I can’t edit the previous comment.
We would like to update a document in Couchbase Server from an app in Android device, and this document will be replicated to CBLite embedded in the app (if the replication filter allows).
oberon
February 14, 2014, 8:46am
5
I’m using Ektorp, we would like to do with Ektorp. But after much test, we also tried with REST api and neither could.
I understand that in the GrocerySync example you point me, you update a CBLite document, and CBLite makes a push replication to Couchbase Server.
We would like to update a document in Couchbase Server from, and this document will be replicated to CBLite if the filter allows.
I’m using CBLite beta2 version.
Many thanks for the quick reply.
oberon
February 14, 2014, 8:58am
6
Hi jliu,
I Reread my question, and I see I did not explain properly.
In a comment below I think I better explain my question.
Among the things I tried, I tested with a put request, like: http://docs.couchbase.com/couchbase-lite/cbl-api/#put-dbdoc , but it didn’t work for me.
Regards.
oberon
February 21, 2014, 12:16pm
7
I realized that I was using an earlier version. I upgraded to the new beta 2, and it worked!!