Question

I am trying to save a new Document in CouchbaseLite but facing this issue, getting exception.

com.couchbase.lite.CouchbaseLiteException

Exception Message:

com.couchbase.lite.CouchbaseLiteException
com.couchbase.lite.CouchbaseLiteException
null
[1462915328, 451, 1462915272, 5, 1463020336, 137, 1463020280, 9, 1462744624, 39,        1462943280, 4, 1463283568, 58, 1463284808, 9, 1459791184, 28, 1463191704, 0, 1463287160, 0, 1463294584, 8, 1463285984, 2, 1463298952, 2, 1461828864, 24, 1459658792, 6, 1461922408, 22, 1459660472, 15, 1461916072, 3, 1461898944, 8, 1459489944, 18, 1459609664, 2, 1459600392, 2, 1459600456, 4, 1460186072, 84, 1460049056, 48, 1459080768, 0, 1459081896, 17, 1460208056, 11, 1460002968, 66, 1459100640, 0]
null
Status: 400
[]

Thought the exception is not clear that what is happening behind, I do not know what to do, what to interpret from it.

Here is my code:

Map<String, Object> map = new HashMap<String, Object>();
    map = (Map<String, Object>) gson.fromJson(json, map.getClass());
    //map.put("_id", UUID.randomUUID().toString());

    Document document = mDatabaseLocal.createDocument();

    try {
        document.putProperties(map);
    } catch (CouchbaseLiteException e) {
        e.printStackTrace();
    }
Was it helpful?

Solution

After making a lot of research on this:

I found that you should not have any property in your map which has a key starting with underscore character '_' because it is reserved for CouchbaseLite.

CouchbaseLite currently does not give you a proper exception message for this so you will be stuck. The only thing you need to take care is to not to include any such key in your map.

Like if you have _id and _rev fields in your class(obj) then you need to remove them

map.remove("_id");
map.remove("_rev");

before calling:

try {
        document.putProperties(map);
    } catch (CouchbaseLiteException e) {
        e.printStackTrace();
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top