Atharva Shukla
Atharva Shukla

Reputation: 2137

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 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?

Upvotes: 0

Views: 36

Answers (1)

Renaud Tarnec
Renaud Tarnec

Reputation: 83093

In Firebase SDKs you will find DocumentReferences and CollectionReferences.

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.

Upvotes: 2

Related Questions