在我的数据库中,一个部分有10000多条记录。我只想查询我特定的索引,如第56 ... 96。我可以这样做吗?
let ref: FIRDatabaseReference = FIRDatabase.database().reference()
let q = (ref.child("WORLDS").queryOrdered(byChild: "publishTime"))
q.queryLimited(toLast: 40)
q.observe(.value, with: { (snap) in ...
就像我刚刚获得最后40条记录一样
答案 0 :(得分:1)
每次在某个位置或查询上调用queryLimited
时,都会返回一个新查询。因此,您需要确保保留对该新查询的引用:
let ref: FIRDatabaseReference = FIRDatabase.database().reference()
let q = (ref.child("WORLDS").queryOrdered(byChild: "publishTime"))
let q2 = q.queryLimited(toLast: 40)
q2.observe(.value, with: { (snap) in ...
或者只是:
let ref: FIRDatabaseReference = FIRDatabase.database().reference()
let query = (ref.child("WORLDS").queryOrdered(byChild: "publishTime")).queryLimited(toLast: 40)
query.observe(.value, with: { (snap) in ...