如何使用 Cloud Firestore 在颤振中设置参考选择数组的条件 [英] how to set where condition on array of reference selection in flutter using Cloud Firestore

查看:11
本文介绍了如何使用 Cloud Firestore 在颤振中设置参考选择数组的条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自 MySql 背景,刚接触 Firebase 云数据库.

I'm from MySql background, new to the firebase cloud database.

如何选择具有区域一的产品列表?

How to select the list of products having zone one?

Mysql:select * from products where product.status=true and zoneIds.name in ("604307") and zoneIds.status=true;

我的 Flutter 代码

My Flutter code

class DatabaseManager {

  final CollectionReference collection =
      FirebaseFirestore.instance.collection('products');
  
  Stream<QuerySnapshot> getStream() {
    return collection.where('status', isEqualTo: true).snapshots();
  }

如何在此添加条件?

return collection.where('status', isEqualTo: true).snapshots();

另外,建议我如何在firebase中做外键引用的概念

Also, suggest to me how to do the foreign key reference concept in firebase

推荐答案

Firestore 支持数组查询.您可以添加如下条件:

Firestore supports array queries. You can add the condition something like this:

return collection
        .where('status', isEqualTo: true)
        .where('zoneIds', arrayContainsAny: ['1'])
        .snapshots();

您可以在此处参考有关查询的 FlutterFire 文档.

You can refer the FlutterFire documentation on querying here.

这篇关于如何使用 Cloud Firestore 在颤振中设置参考选择数组的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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