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

后端 未结 5 1245
无人及你
无人及你 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:39

    Probably the simplest solution is to set the value of a reference key to a doc(collection/doc_key) because a DocumentReference is needed.

    Example code:

    post = {
      content: "content...",
      title: "impressive title",
      user: db.doc('users/' + user_key),
    };
    
    db.collection('posts').add(post)
    

提交回复
热议问题