Get data ordered by document Id in Firestore by Javascript?

喜欢而已 提交于 2021-02-07 14:23:23

问题


Get data ordered by document Id in Firestore by Javascript

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);

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);

It give a error:

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

Any idea? Thank you for your help.


回答1:


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()



来源:https://stackoverflow.com/questions/52772169/get-data-ordered-by-document-id-in-firestore-by-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!