通过Javascript获取Firestore中按文档ID排序的数据? [英] Get data ordered by document Id in Firestore by Javascript?

查看:49
本文介绍了通过Javascript获取Firestore中按文档ID排序的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Javascript在Firestore中获取按文档ID排序的数据

Get data ordered by document Id in Firestore by Javascript

在Andorid中,我可以使用查询转到特定文档

In Andorid, I can use the query go to specific documents

mQuery = docRef.whereEqualTo("name", name)
                .whereEqualTo("valid",true)
                .orderBy(FieldPath.documentId())
                .startAt(lastDocId)
                .limit(LIMIT);

它可以工作,但是在Javascript中,我尝试复制类似的查询,这没用.

It works, but in Javascript, I try to copy a similar query, it didn't work.

var db = firebase.firestore();
    var goQuery = docRef.where("name", "==", name)
                        .where("valid", "==", true)
                        .orderBy(db.FieldPath.documentId())
                        .startAfter("id0070")
                        .limit(LIMIT);

出现错误:

未捕获的TypeError:无法读取未定义的属性'documentId'在HTMLButtonElement.document.getElementById.onclick

Uncaught TypeError: Cannot read property 'documentId' of undefined at HTMLButtonElement.document.getElementById.onclick

有什么主意吗?谢谢您的帮助.

Any idea? Thank you for your help.

推荐答案

通过反复试验,正确的语法是

By trial and error, the correct grammar is

var goQuery = docRef.where("name", "==", name)
                    .where("valid", "==", true)
                    .orderBy(firebase.firestore.FieldPath.documentId())
                    .startAfter("id0070")
                    .limit(LIMIT);

firebase.firestore.FieldPath.documentId()

这篇关于通过Javascript获取Firestore中按文档ID排序的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆