Skip to main content

Document reference

A document reference is a reference to a specific record in a collection. You can use it to read or write data to the document.

Document basics

A document can refer to a row in a table in a relational database or a document in a NoSQL database. A document reference acts as a pointer to a specific row or document in the database. Additionally, a document reference can refer to a non-existent document, which you can use to create a new document.

To get a single reference to a document in a collection, use the collectionRef.doc(id) method:

Client code
userRef = usersCollectionRef.doc(userId);

This provides a reference to the specified user's document within that collection.

Once you have a reference to a document, you can perform various operations on it, such as querying the document for its data, or inserting, updating, or deleting the document.