Error when running map reduce in CouchBase Lite


#1

Hi guys,

I am trying to use map-reduce on CouchBase Lite. I have documents and they are being channelised. All doucments what I want are coming to Couchbase Lite. But When I Try to run map-reduce on them I am getting the following error

com.couchbase.lite.CouchbaseLiteException: Error when calling map block of view 'calendar', Status: 593 (HTTP 500 Application callback block failed)

Below is my map reduce function

private View createView(Database database){ View calendarView = database.getView("calendar"); calendarView.setMap(new Mapper() { @Override public void map(Map<String, Object> document, Emitter emitter) { emitter.emit((long) document.get("date"),(long) document.get("cost")); } },"2"); return calendarView; }

and Below is the part of main where I am calling the view and querying over it

View calendarView = createView(database); Query query = database.getView("calendar").createQuery(); query.setStartKey(1472467249448l); query.setEndKey(1472553649449l); QueryEnumerator result = null; try { result = query.run(); } catch (CouchbaseLiteException e) { e.printStackTrace(); } for (Iterator<QueryRow> it = result; it.hasNext(); ) { QueryRow row = it.next(); Log.d(TAG, row.getValue().toString()); }


#2

The error is Application callback block failed, i.e. your map function threw an exception. Most likely it encountered a doc without a date or a cost property, or perhaps the property type was not convertible to long.


#3

all my documents are like below

{ "_sync": { "rev": "1-16a9b6239a1a2da1bb2d5896f17adf02", "sequence": 73, "recent_sequences": [ 73 ], "history": { "revs": [ "1-16a9b6239a1a2da1bb2d5896f17adf02" ], "parents": [ -1 ], "channels": [ [ "InLineCalendar" ] ] }, "channels": { "InLineCalendar": null }, "upstream_cas": 1464000049527390200, "upstream_rev": "1-16a9b6239a1a2da1bb2d5896f17adf02", "time_saved": "2016-05-23T17:33:52.299758583+05:30" }, "channels": [ "InLineCalendar" ], "cost": 1909, "date": 1467369649448 }

Is there anyway I can check whether a particular field is in a document then only process it via map function else neglect it.

Something like this

if(document.get(“cost”))
{
//emit
}
else{
//neglect the document
}


#4

Yes, exactly like that.