Firestore - How create DocumentReference using path String

Yes, you can achieve this also in Cloud Firestore. So these are your options:

FirebaseFirestore db = FirebaseFirestore.getInstance();

First option:

DocumentReference userRef = db.collection("company/users");

Second option:

DocumentReference userRef = db.document("company/users");

Third option:

DocumentReference userRef = db.collection("company").document("users");

For web/javascript, db.doc() will create a DocumentReference from a string:

let docRef = db.doc(pathString)

e.g. let userRef = db.doc('users/' + userId)


You can use FirebaseFirestore.document() and pass it the path of the document you want. Each document must be located within a collection. If you're looking for a document called documentId in a collection called collectionId, the path string will be collectionId/documentId.