Firebase Firestore endBefore不';不排除锚定文档

Firebase Firestore endBefore不';不排除锚定文档,firebase,google-cloud-firestore,Firebase,Google Cloud Firestore,嘿,我正在尝试用上一个和下一个模型实现分页 下一个分页工作正常 但是前面的分页没有按预期工作,endBefore不排除锚定/光标文档。我正在使用firebase管理SDK 这是我的密码 const { firestore } = require('../config/db') const db = firestore.collection('pet_action_logs') const limit = 5 async function getLogs(pet_id) { return

嘿,我正在尝试用上一个和下一个模型实现分页

下一个分页工作正常

但是前面的分页没有按预期工作,
endBefore
不排除锚定/光标文档。我正在使用firebase管理SDK

这是我的密码

const { firestore } = require('../config/db')
const db = firestore.collection('pet_action_logs')
const limit = 5

async function getLogs(pet_id) {
    return await db.where('pet_id', '==', pet_id).orderBy('created_at', 'desc').limit(limit).get()
}

async function getPrevious(pet_id, endBefore) {
    return await db.where('pet_id', '==', pet_id).orderBy('created_at', 'desc').endBefore(new Date(endBefore * 1000)).limitToLast(limit).get() 
}

async function getNext(pet_id, startAfter) {
    return await db.where('pet_id', '==', pet_id).orderBy('created_at', 'desc').startAfter(new Date(startAfter * 1000)).limit(limit).get()
}

module.exports = {
    getLogs,
    getPrevious,
    getNext
}


作为一种解决方法,我使用
offset
排除锚定文档。 因此,我以前的分页页面如下所示:

async function getPrevious(pet_id, endBefore) {
    // this is very hacky, if not using `offset`, the anchor document is included, so i need to use `offset` to skip the first document
    return await db.where('pet_id', '==', pet_id).orderBy('created_at', 'desc').endBefore(new Date(endBefore * 1000)).limitToLast(limit).offset(1).get() 
}


有人能给我解释一下为什么会发生这种情况吗?

Hi@irfangumeral我建议您测试一些不同的方法,比如,删除
async
,这样在运行它们时函数就不是异步的,甚至删除
new Date()
,并将其作为变量直接运行,因为这可能也会影响它。你能试试吗?