简体   繁体   中英

Are references only for Documents in Firestore?

Okay, so there is this "Reference" thing that I don't get about 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? So how is that different?

In Firebase SDKs you will find DocumentReference s and CollectionReference s.

A DocumentReference refers to a document location in a Firestore database and can be used to write, read, or listen to the location. 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.

Note that a CollectionReference can refer to root collections as well as to sub-collections under a Document.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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