In Cloud function how can i join from another collection to get data?

前端 未结 3 1578
旧巷少年郎
旧巷少年郎 2021-01-26 04:34

I am using Cloud Function to send a notification to mobile device. I have two collection in Firestore clientDetail and clientPersonalDetail. I have

3条回答
  •  误落风尘
    2021-01-26 05:39

    You can use two extra functions in this occasion to have your code clear. One function that will read all the documents form the collection ClientDetail and instead of getting all the fields, will get only the ClientID. Then call the other function, that will be scanning all the documents in collection ClientPersonalDetail and retrieve only the part with the ClientID. Compare if those two match and then do any operations there if they do so.

    You can refer to Get started with Cloud Firestore documentation on how to create, add and load documents from Firestore.

    Your package,json should look something like this:

    {
      "name": "sample-http",
      "version": "0.0.1",
      "dependencies": {
        "firebase-admin": "^6.5.1"
      }
    }
    

    I have did a little bit of coding myself and here is my example code in GitHub. By deploying this Function, will scan all the documents form one Collection and compare the ClientID from the documents in the other collection. When it will find a match it will log a message otherwise it will log a message of not matching IDs. You can use the idea of how this function operates and use it in your code.

提交回复
热议问题