11
votes

Firebase realtime database allowed to create refrence using

 var reference = db.ref(path);

Is there any method exist in firestore so that I can create document refrence using path String.

If method exists how can I find path string in android and then how create document reference in node.js using that path.

4

4 Answers

29
votes

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");
4
votes

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)

2
votes

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.

0
votes

you just need to define the path :

`users/${type}/${user.uid}/`

firestore
  .collection(`users/${type}/${user.uid}/`)
  .add(documentData)
  .then(function () {
    message = { message: "document added", type: ErrorType.success };
  })
  .catch(function (error) {
    message = { message: error, type: ErrorType.error };
  });