I’m trying to use a CBLView for indexing/filtering the documents on two channels, having the key “waitMinutes” and emitting the document id and the document itself:
func queryFacilityStatuses () -> CBLQuery{
let view : CBLView = database.viewNamed("facilityStatuses")
if (view.mapBlock == nil) {
view.setMapBlock({ (document, emit) in
if (document.index(forKey: "waitMinutes") != nil) {
emit(document["id"], document) //Breakpoint here
}
}, version: "0.0.6")
}
return view.createQuery()
}
When the emit function is called for any document with this structure, an exception is presented. I put a breakpoint on the emit line and printed the document:
po print(document)
["singleRider": 0, "status": Operating, "_id": dlr.facilitystatus.1_0.Attraction.353451, "id": 353451;entityType=Attraction, "channels": <__NSArrayM 0x600000c53aa0>(
dlr.facilitystatus
)
, "fastPassEndTime": , "waitMinutes": 50, "_rev": 1-47ddbd3d993086de0be5947b426ed986, "fastPassAvailable": 1, "fastPassStartTime": FASTPASS is Not Available, "_local_seq": 1]
This is the document on the Sync Gateway:
{
"channels": [
"dlr.facilitystatus"
],
"fastPassAvailable": true,
"fastPassEndTime": "",
"fastPassStartTime": "FASTPASS is Not Available",
"id": "353451;entityType=Attraction",
"singleRider": false,
"status": "Operating",
"waitMinutes": 50,
"_rev": "1-47ddbd3d993086de0be5947b426ed986",
"_id": "dlr.facilitystatus.1_0.Attraction.353451"
}
And this is the exception trace:
08:23:27.725‖ WARNING: Exception caught in map block of view facilityStatuses, on doc {
"_id" = "dlr.facilitystatus.1_0.Attraction.353451";
"_local_seq" = 1;
"_rev" = "1-47ddbd3d993086de0be5947b426ed986";
channels = (
"dlr.facilitystatus"
);
fastPassAvailable = 1;
fastPassEndTime = "";
fastPassStartTime = "FASTPASS is Not Available";
id = "353451;entityType=Attraction";
singleRider = 0;
status = Operating;
waitMinutes = 50;
}:
Invalid type in JSON write (_SwiftValue)
3 Foundation 0x0000000111263284 _writeJSONValue + 668
4 Foundation 0x00000001112636d9 ___writeJSONArray_block_invoke + 132
5 CoreFoundation 0x0000000118e1ce2a -[__NSSingleObjectArrayI enumerateObjectsWithOptions:usingBlock:] + 58
6 Foundation 0x00000001112633df _writeJSONArray + 330
7 Foundation 0x0000000111263204 _writeJSONValue + 540
8 Foundation 0x0000000111262f94 -[_NSJSONWriter dataWithRootObject:options:error:] + 124
9 Foundation 0x0000000111262e74 +[NSJSONSerialization dataWithJSONObject:options:error:] + 333
10 DLR 0x000000010e50300e NRMA__ptrIntPtrParamHandler + 190
11 DLR 0x000000010e50211c NRMA__blk_ptrIntPtrParamHandler + 60
12 WDPRFinderCore 0x00000001159fc805 +[CBLJSON dataWithJSONObject:options:error:] + 320
13 WDPRFinderCore 0x0000000115a29518 -[CBL_SQLiteViewStorage _emitKey:value:valueIsDoc:forSequence:] + 629
14 WDPRFinderCore 0x0000000115a29033 __39-[CBL_SQLiteViewStorage updateIndexes:]_block_invoke.161 + 97
15 WDPRFinderCore 0x0000000115951bfb _TTRXFdCb_dPs9AnyObject_dGSqPS_____XFo_iP_iGSqP____ + 219
16 WDPRFinderCore 0x0000000115951881 _TFFC14WDPRFinderCore25FacilityStatusServiceImpl21queryFacilityStatusesFT_CSo8CBLQueryU_FTGVs10DictionarySSP__FTP_GSqP___T__T_ + 737
17 WDPRFinderCore 0x000000011595199a _TTRXFo_oGVs10DictionarySSP__oXFo_iP_iGSqP______XFdCb_dCSo12NSDictionarydXFdCb_dPs9AnyObject_dGSqPS1_______ + 170
... {at MYReportException:43}
Additional details:
- The same configuration and documents are being used on an Android App and is working fine.
- When I use createAllDocumentsQuery() instead of the query from a view, the documents are retrieved correctly.
- I’m using Couchbase Lite V1.3.1 and building with Xcode 8.0 and Swift 3
Any help will be appreciated!