I have a document that has a “startBy” (iso date string) and a “name” (string) field in its row value. I need to sort on startBy, and then name secondarily. I set an array of sortDescriptors for both but the query only sorts based on the first descriptor in the array. Is there a reason why it’s only sorting based on the first descriptor and not both?
let view = database.viewNamed("Inspections")
view.setMapBlock({ (doc, emit) in
guard let type = doc["type"] as? String, type == "Inspection" else {
return
}
// Nested JSON object that has "startBy" (date string) and "name" (string)
let value = doc["inspection"] as! [String: Any]
// Make sure its not yet started.
guard value["startedAt"] == nil else {
return
}
// Using "startBy" date string value as key also works to sort by that
let key = value["startBy"]!
emit(key, value)
}, version: "1")
let query = view.createQuery()
let startBy = NSSortDescriptor(key: "value.startBy", ascending: true)
let name = NSSortDescriptor(key: "value.name", ascending: true)
query.sortDescriptors = [startBy, name]