Flutter Firestore查询嵌套子集合 [英] Flutter Firestore Query Nested Subcollections

查看:159
本文介绍了Flutter Firestore查询嵌套子集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查询Firebase中的子集合,但我总是得到一个空列表...



这是我的查询:

  Firestore.instance.collection('messages')。where('idFrom',isEqualTo:userID).snapshots(); 

我知道我有一个子集合,并且这里还有另一个子集合。

  / messages / RWzG98s92mVTZniofez6YoYsNhA3-tT2Q16n1FMZoTNZQOejtWuJdCmD2 / RWzG98s92mVTZniofez6YoYsNhA3-tT2Q $ n $ b $ c 
$ c
$ c
$ c $ b $ c $ b $ c $ b $ c
$ c




$ b $ e

$ b $ e b $ b

我的问题是如何查询这些类型的模型?



解决方案

由于Firstore查询始终很浅,因此您必须构建要查询的子集合的路径。

  Firestore.instance 
.collection('messages')
.document(...)//嵌套文档
的ID。采集(...)。 //嵌套子集合
的ID。where('idFrom',isEqualTo:userID);

没有办法避免提供这些嵌套的ID。如果您无法确定要查询的子集合的完整路径,则将无法访问其文档。


I am trying to query subcollection in Firebase, but I always get an empty list...

This is my query:

Firestore.instance.collection('messages').where('idFrom', isEqualTo: userID).snapshots();

I know that I have subcollection with another subcollection here..

/messages/RWzG98s92mVTZniofez6YoYsNhA3-tT2Q16n1FMZoTNZQOejtWuJdCmD2/RWzG98s92mVTZniofez6YoYsNhA3-tT2Q16n1FMZoTNZQOejtWuJdCmD2/1579394957103

And my question is how to query these types of models?

解决方案

Since Firstore queries are always shallow, you have to build the path to the subcollection to query.

Firestore.instance
    .collection('messages')
    .document(...)   // ID of the nested document
    .collection(...).  // ID of the nested subcollection
    .where('idFrom', isEqualTo: userID);

There is no way to avoid giving those nested IDs. If you can't identify the full path of the subcollection to query, you won't be able to access its documents.

这篇关于Flutter Firestore查询嵌套子集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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