【发布时间】:2019-03-17 06:01:10
【问题描述】:
通过 Javascript 在 Firestore 中获取按文档 ID 排序的数据
在 Andorid 中,我可以使用查询转到特定文档
mQuery = docRef.whereEqualTo("name", name)
.whereEqualTo("valid",true)
.orderBy(FieldPath.documentId())
.startAt(lastDocId)
.limit(LIMIT);
它可以工作,但在 Javascript 中,我尝试复制一个类似的查询, 没用。
var db = firebase.firestore();
var goQuery = docRef.where("name", "==", name)
.where("valid", "==", true)
.orderBy(db.FieldPath.documentId())
.startAfter("id0070")
.limit(LIMIT);
它给出一个错误:
未捕获的类型错误:无法读取未定义的属性“documentId” 在 HTMLButtonElement.document.getElementById.onclick
有什么想法吗?感谢您的帮助。
【问题讨论】:
-
为什么一个是
FieldPath.documentId(),另一个是db.FieldPath.documentId()? -
回复 epascarello:导致 FieldPath.documentId() 会报错:Uncaught ReferenceError: FieldPath is not defined
-
@MikeLin 我不认为你明白他的意思。这就是为什么第一个称为 db.FieldPath 而另一个称为 FieldPath。
标签: javascript google-cloud-firestore