Firestore:从“子"集合中获取所有项,其中id = x [英] Firestore: Get all items from a 'sub' collection where id = x

查看:47
本文介绍了Firestore:从“子"集合中获取所有项,其中id = x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Cloud Firestore用于后端数据库,因为我不太熟悉它.

数据库设置:消息(集合)-> itemId(文档)-> itemMessages(集合)->消息(doc)->带有(消息,xId,yId)的消息数据

我的问题是..如何查询xid = 1的itemId的所有itemMessages?

或者对于数据库设置是否有更好的解决方案?我已经检查了文档,但是在示例中这些文档不是'sub'集合.

解决方案

[此处为Firebaser] 符合您查询条件的项目",您将无法做到.

您可以像这样查询特定的子集合:

  db.collection(消息").doc("someItemId").collection("itemMessages").where("xid","==","foobar") 

将来肯定要在子集合中进行查询的功能,但是短期内不会用到,因此如果您现在需要,我建议使用其他数据库结构.

I'm using cloud firestore for the backend DB and since I'm not that familiar with it.. i'm a bit stuck on the following.

DB setup: Messages (collection) -> itemId (doc) -> itemMessages (collection) -> Message (doc) -> the message data with (message, xId, yId)

My question is.. how can I query all the itemMessages for itemId where xid = 1?

Or is there a better solution for the DB setup? I have checked the docs, but those didn't a 'sub' collection in the examples.

解决方案

[Firebaser here] There is no way to query across subcollections, meaning if you wanted to find all of the itemMessages belonging to any "item" that match your query, you cannot do that.

You could query a specific subcollection like this:

db.collection("Messages")
  .doc("someItemId")
  .collection("itemMessages")
  .where("xid", "==", "foobar")

The feature to query across subcollections is something we definitely want to do in the future but it will not come in the short term so if you need that right now I would suggest a different database structure.

这篇关于Firestore:从“子"集合中获取所有项,其中id = x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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