Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore - How create DocumentReference using path String

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.

like image 311
Parvesh Monu Avatar asked Jun 06 '18 14:06

Parvesh Monu


People also ask

What is firestore document path?

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 DocumentReference can also be used to create a CollectionReference to a subcollection.

How do you create a reference for a document?

Citation includes author's name, year of publication, then page numbers if available. If your source lacks an author, cite the first one or two words of the title. If no date is given, place "n.d." after the author's name. note on page numbers: Web documents often don't have page numbers.


2 Answers

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");
like image 73
Alex Mamo Avatar answered Oct 11 '22 22:10

Alex Mamo


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)

like image 22
Darren G Avatar answered Oct 11 '22 21:10

Darren G