Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript firestore中的引用类型_Javascript_Firebase_React Native_Google Cloud Firestore - Fatal编程技术网

Javascript firestore中的引用类型

Javascript firestore中的引用类型,javascript,firebase,react-native,google-cloud-firestore,Javascript,Firebase,React Native,Google Cloud Firestore,我正在尝试在firestore中实现documentreference。我创建了两个集合:客户和购买的财产。每次在Purchased-Property集合中创建新文档时,如何在Purchased-Property\u Customer\u id中引用Customer\u id。 代码如下所示: const CustomerDoc = firebase.firestore().collection("Customers").doc() CustomerDoc.set({

我正在尝试在firestore中实现documentreference。我创建了两个集合:
客户
购买的财产
。每次在
Purchased-Property
集合中创建新文档时,如何在
Purchased-Property\u Customer\u id
中引用
Customer\u id
。 代码如下所示:

 const CustomerDoc = firebase.firestore().collection("Customers").doc()
CustomerDoc.set({
       Customer_id: CustomerDoc.id,
       Customer_Name: Name
       Customer_PhoneNumber: PhoneNumber

    })

const PurchasedPropertyDoc = firebase.firestore().collection("Purchased-Property").doc()
    PurchasedPropertyDoc.set({
           Purchased_Property_id: PurchasedPropertyDoc.id,
           Purchased_Property_Name: Property_Name,
           Purchased_Property_Location: Property_Location,
           Purchased_Property_Customer_Id: Customer_Id   //How do i make  reference to this Customer_Id in the Customers collection everytime a new document under the Purchased-Property collection is made 


    
        })

CustomerDoc
是一个对象。每个DocumentReference都有一个
id
属性。您可以这样简单地使用它:

    PurchasedPropertyDoc.set({
           Purchased_Property_id: PurchasedPropertyDoc.id,
           Purchased_Property_Name: Property_Name,
           Purchased_Property_Location: Property_Location,
           Purchased_Property_Customer_Id: CustomerDoc.id
    })

这与您在第一个文档中首次使用
CustomerDoc.id
的方式没有什么不同。如果您在创建文档时没有此引用,那么您将无法建立关联。

那么我如何使用引用数据类型来更方便地定位
客户Id
,因为上面的答案是正确的,所以使用引用类型将其存储为字符串并不一定简单。您仍然需要查询另一个文档。但如果需要引用,您可以直接传递
CustomerDoc