Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save reference to other collection

How do you save a reference to another collection within Firebase Firestore? The docs on adding data doesn't mention anything about saving references.

like image 302
Michael Falck Wedelgård Avatar asked Nov 22 '17 09:11

Michael Falck Wedelgård


1 Answers

Firestore supports storing of a reference to a document (DocumentReference) rather than to a collection, but you can add a DocumentReference to the database just like any other supported data type, something like this in JavaScript:

db.collection("cities").doc("LA").set({
    name: "Los Angeles",
    state: db.collection("states").doc("CA"),
    country: "USA",
});
like image 69
Grimthorr Avatar answered Sep 22 '22 21:09

Grimthorr