You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a swift iOS application that is using a map/reduce block, the respective live query is not working properly. Below is the code excerpt:
Couchbase document has below field and type structure:
fID String
rStatus Bool
tID String
mDate: String with date entries as provided by CBLJSON.jsonObject(with: Date())
`if let aView: CBLView = self.database?.viewNamed("rView"){
aView.setMapBlock({ (doc, emit) in
if let fID = doc["fID"] as? String,
let tID = doc["tID"] as? String,
let rStatus = doc["rStatus"] as? NSNumber,
let dt = doc["mDate"] as? String, let date = CBLJSON.date(withJSONObject: dt){
let timeStamp = dt.timeIntervalSince1970
//Two times emit is to be able to get latest data based on grouping
emit([fID,rStatus,tID,timeStamp],doc)
emit([tID,rStatus,fID,timeStamp],doc)
}
}, reduce: { (keys, values, rereduce) -> Any in
var data = [String: Any]()
if let valueArray = values as? [[String: Any]]{
do{
let lIndex = valueArray.count - 1
if lIndex < 0{
return data
}
let lastObject = valueArray[lIndex]
data["fID"] = lastObject["fID"]
data["toId"] = lastObject["tID"]
data["rStatus"] = lastObject["rStatus"]
let mDate = lastObject["mDate"]
data["mDate"] = mDate
let date = CBLJSON.date(withJSONObject: mDate)
let tStamp = date?.timeIntervalSince1970
data["tStamp"] = tStamp
}
catch{
print("Encountered error: \(error).")
}
}
//print("Data is: \(data)")
return data
}, version: "1")
}`
The query setup code is as below:
`if let aView = self.database?.existingViewNamed("rView"){
aQuery = aView.createQuery().asLive()
if let query = aQuery{
var keysArray = Any
keysArray.append(fID) //Here fID and tID from document is a string beginning with letter G followed by two colons and then an integer value for example G::101, G::108, G::99 etc
query.startKey = keysArray
keysArray.append([:])
query.endKey = keysArray
query.groupLevel = 3 //To group on basis of first three keys in the emitted keys
query.addObserver(self, forKeyPath: "rows", options: [.new,.initial], context: nil)
}
}
`
I have ensured that the value specified in startKey and endKey do exists in the database and getting synced. The above query expects to return most recent data based on timeStamp and grouped too as per specified group level. The issue being faced is:
The above query is not respecting the values specified in startKey and endKey fields and so is not returning complete data. Here by complete data I mean some documents gets excluded from the returned result set even though they are having correct values as specified by the startKey and endKey.
I have noticed that keys array parameter of reduce block contains a collection with each row having four elements instead of three as per specified groupingLevel of 3.
Any idea, what is going wrong in here?
Version: Couchbase lite SDK version: 1.4.1
Client OS: iOS 11
Server: Couchbase Sync Gateway/1.4.1
The text was updated successfully, but these errors were encountered:
Regarding the issue bout the keys array parameter, I have checked with @snej about this, and it's correct that there are four items in the keys array. Here is the info from @snej:
Jens Alfke: The way reduce is called doesn't depend on the groupLevel. Conceptually, reduce happens at indexing time (it does in CouchDB; it doesn't in CBL just because we didn't have a good way to store the reduced values.)
Jens Alfke: So the keys passed to reduce are always the same as the keys the map block emits.
For a swift iOS application that is using a map/reduce block, the respective live query is not working properly. Below is the code excerpt:
Couchbase document has below field and type structure:
fID String
rStatus Bool
tID String
mDate: String with date entries as provided by CBLJSON.jsonObject(with: Date())
`if let aView: CBLView = self.database?.viewNamed("rView"){
aView.setMapBlock({ (doc, emit) in
if let fID = doc["fID"] as? String,
let tID = doc["tID"] as? String,
let rStatus = doc["rStatus"] as? NSNumber,
let dt = doc["mDate"] as? String, let date = CBLJSON.date(withJSONObject: dt){
The query setup code is as below:
`if let aView = self.database?.existingViewNamed("rView"){
aQuery = aView.createQuery().asLive()
if let query = aQuery{
var keysArray = Any
keysArray.append(fID) //Here fID and tID from document is a string beginning with letter G followed by two colons and then an integer value for example G::101, G::108, G::99 etc
query.startKey = keysArray
}
`
I have ensured that the value specified in startKey and endKey do exists in the database and getting synced. The above query expects to return most recent data based on timeStamp and grouped too as per specified group level. The issue being faced is:
Any idea, what is going wrong in here?
The text was updated successfully, but these errors were encountered: