I want to make a Firestore
call in a collection
which excludes some values on a field. This is the snippet of code I wrote
db.collection("MyCollection")
.order(by: "timestamp", descending: false)
.whereField("timestamp", isGreaterThan: localTimestamp)
.whereField("uid", notIn: [reportedUids, currentUid])
.limit(to: 3)
.getDocuments { (snapshot, error) in
if let err = error{
print(err.localizedDescription)
return
}
var modelsData = [Model]()
snapshot?.documents.forEach({ (doc) in
let dict = doc.data()
var model = Model()
model.transformModelWith(dict: dict)
modelsData.append(model)
})
let lastDocumentFetched = snapshot?.documents.last
DispatchQueue.main.async {
completion(modelsData, lastDocumentFetched!)
}
}
}
The error I get when running this is:
Invalid query. You have a where filter with an inequality (notEqual, lessThan, lessThanOrEqual, greaterThan, or greaterThanOrEqual) on field 'uid' and so you must also use 'uid' as your first queryOrderedBy field, but your first queryOrderedBy is currently on field 'timestamp' instead.'
And searching online it brings me here, my question is:
how can I approach this problem if I necessarily need to exclude some data from the query?