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. Assuming you have a collection reference to the users collection, to obtain a document reference to some user with ID userId, you can do the following:

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 getting a current snapshot, listening for changes, or inserting, updating, or deleting the document. These topics are covered later in the queries and mutations documentation. Continue reading the documentation to find out more about the range of functionality the Client SDK offers.