简体   繁体   English

如何在 firebase firestore 中使用 isEqualTo 和 isNotEqualTo 查询数据

[英]How to query data with isEqualTo and isNotEqualTo in firebase firestore

The below query stop working when I add .where('user_id', isNotEqualTo: currentUser..id) How can i fetch data with isEqualTo and isNotEqualTo in firebase firestore?当我添加.where('user_id', isNotEqualTo: currentUser..id)时,以下查询停止工作 如何在 firebase 防火墙中使用 isEqualTo 和 isNotEqualTo 获取数据?

  Future<int> unreadMessages(String id) async {
    int message = 0;
    await messageRef
        .doc(id)
        .collection('items')
        .where('read', isEqualTo: 0)
        .where('user_id', isNotEqualTo:10)
        .get()
        .then((value) {
      message = value.docs.length;
    });
    return message;
  }

You need to create a composite index if you combine equality operators with inequality operators.如果将等式运算符与不等式运算符结合使用,则需要创建复合索引。

The official documentation describes this.官方文档对此进行了描述。

https://firebase.google.com/docs/firestore/query-data/queries#compound_queries https://firebase.google.com/docs/firestore/query-data/queries#compound_queries

There is probably an error text in your console that inform you about this, even with a direct link you can click on that creates that index.您的控制台中可能有一条错误文本通知您这一点,即使您可以单击创建该索引的直接链接。

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

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