简体   繁体   English

仅对 Firestore 中的文档进行引用吗?

[英]Are references only for Documents in Firestore?

Okay, so there is this "Reference" thing that I don't get about Firebase:好吧,关于 Firebase,我没有得到这个“参考”的东西:

const docRef = firestore.collection('users').doc();

You can you get a "reference" of a Document but you can't get a reference of a Collection?您可以获得文档的“参考”但无法获得集合的参考吗?

Why?为什么?

Clearly there can be multiple docs in a collection but there can also be multiple collections in a doc, right?显然一个集合中可以有多个文档,但一个文档中也可以有多个 collections,对吧? So how is that different?那有什么不同呢?

In Firebase SDKs you will find DocumentReference s and CollectionReference s.在 Firebase SDK 中,您将找到DocumentReferenceCollectionReference

A DocumentReference refers to a document location in a Firestore database and can be used to write, read, or listen to the location. DocumentReference指的是 Firestore 数据库中的文档位置,可用于写入、读取或收听该位置。 The document at the referenced location may or may not exist.引用位置的文档可能存在也可能不存在。

A CollectionReference object can be used for adding documents, getting document references, and querying for documents. CollectionReference object 可用于添加文档、获取文档引用和查询文档。

Note that a CollectionReference can refer to root collections as well as to sub-collections under a Document.请注意, CollectionReference可以引用根 collections 以及文档下的子集合。

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

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