简体   繁体   English

如何为查询创建索引使用文档ID Cloud Firestore

[英]How to create index for a query uses the document id cloud firestore

I am using this query in my android app : 我在我的android应用程序中使用此查询:

        fireStoreQuestions.document(subject).collection(subject)
            .whereEqualTo("reviewed", true)
            .whereGreaterThan(FieldPath.documentId(), randomId)
            .limit(1)
            .get()

I want to know how to add an index to this query in cloud firestore. 我想知道如何在Cloud Firestore中向此查询添加索引。 I don't know how to represent the document id in the index. 我不知道如何在索引中表示文档ID。

You can create the index manually in your Firebase Console or if you are using Android Studio, you'll find in your logcat a message that sounds like this: 您可以在Firebase控制台中手动创建索引 ,或者如果您使用的是Android Studio,则在logcat中会看到一条听起来像这样的消息:

W/Firestore: (0.6.6-dev) [Firestore]: Listen for Query(subject where reviewed == true and id > randomId) failed: Status{code=FAILED_PRECONDITION, description=The query requires an index. W / Firestore:(0.6.6-dev)[Firestore]:侦听查询(主题已审核== true和id> randomId)失败:状态{code = FAILED_PRECONDITION,description =查询需要索引。 You can create it here: https://console.firebase.google.com/project/ ... 您可以在这里创建它: https : //console.firebase.google.com/project/ ...

So you can simply click on that link or copy and paste the url into a web broswer and you index will be created automatically. 因此,您只需单击该链接或将URL复制并粘贴到网络浏览器中,即可自动创建索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM