Android: QueryRow.getDocumentId() returning null



I am querying a simple view and getting null when asking for QueryRow.getDocumentId();

The view is defined as:

// Create View for Event List
        View expensesView = database.getView("expenseList");
        expensesView.setMapReduce(new Mapper() {
            public void map(Map<String, Object> document, Emitter emitter) {
                if ("expense".equals(document.get("type"))) {
                    List<Object> key = new ArrayList<>();
                    emitter.emit(key, document.get("amount"));
        }, new Reducer() {
            public Object reduce(List<Object> keys, List<Object> values, boolean rereduce) {
                float sum = 0;
                for (Object f : values) {
                    float val = ((Number) f).floatValue();
                    sum += val;
                return sum;
        }, "2");

Now, when I try to query this View and try to get the source document Id, I am getting null.

Query query = app.getDatabase().getView("expenseList").createQuery();
query.setStartKey(Arrays.asList(eventId, new HashMap<String, Object>()));
//Query for Results
QueryEnumerator result =;
for (Iterator<QueryRow> it = result; it.hasNext(); ) {
    QueryRow row =;
    String key = row.getKey().toString();
    String value = row.getValue().toString();
    Log.d("DatabaseHelper", "key:" + key + ", value:" + value + ", _id:" + row.getDocumentId() + "|" + row.getSourceDocumentId());

What I am getting output is:

key:[84ca9d7d-02d1-4c4a-bded-6f5b1a0cdf56, 1454924927419], value:400.0, _id:null|null
key:[84ca9d7d-02d1-4c4a-bded-6f5b1a0cdf56, 1454924308837], value:300.0, _id:null|null
key:[84ca9d7d-02d1-4c4a-bded-6f5b1a0cdf56, 1454924300656], value:200.0, _id:null|null
key:[84ca9d7d-02d1-4c4a-bded-6f5b1a0cdf56, 1454924283069], value:100.0, _id:null|null

How can any query return the document Id null ? It always has the source document id from which it was emitted.

Is there any point which I missed?


You’re aggregating query rows by setting the groupLevel to 2, so they no longer correspond to individual documents.


Ohh. I misunderstood it.

Can you please give me an example for groupLevel?. I misunderstood it with the startKey and endKey with array example.


Here is the documentation for grouping.