How do you insert a “reference” value into firestore?

后端 未结 5 1212
无人及你
无人及你 2020-12-24 01:50

I\'m trying to insert a document into a collection. I want the document to have a attribute of type reference to insert into the collection. But every time I in

5条回答
  •  一生所求
    2020-12-24 02:50

    I was trying to figure this out today and the solution I came to was to use the .doc() to create a doc reference

      firebase.firestore()
        .collection("applications")
        .add({
          property: firebase.firestore().doc(`/properties/${propertyId}`),
          ...
        })
    

    This will store a DocumentReference type on the property field so when reading the data you will be able to access the document as so

      firebase.firestore()
        .collection("applications")
        .doc(applicationId)
        .get()
        .then((application) => {
          application.data().property.get().then((property) => { ... })
        })
    

提交回复
热议问题