【问题标题】:Retrieve friend's name from firebase firestore in functions从函数中的firebase firestore检索朋友的名字
【发布时间】:2018-06-06 02:20:15
【问题描述】:

在 Firebase 函数中检索我朋友的名字和姓氏的最佳方法是什么?我尝试了几种方法,但都不起作用。

  1. 用户集合。
  2. Persons_id 是自动生成的文档 ID。
  3. Friends 是一个带有 person_id 的对象数组。
  4. Name 的对象是 first 和 last。

我正在使用文档 ID 发出一个 http 请求,并以我朋友的名字/姓氏数组进行响应。

const id = String(req.body.id);
admin.firestore().collection('users').doc(id);

friends = [];
friends.push(jsonObject); // not sure if i should do a for loop
res.send({ friends: friends }); // responding with array

Firestore:

Users (collection)
"c7xXQC5cEq5JyWyED8rX" (document)
name: {
  first: "John",
  last: "Doe",
},
friends: [ {
  persons_id: "0fLXpei6kEgrCkfFCeJi",
  confirmed: true,
},
  persons_id: "65ghQC5cEq5JyWyED8rX",
  confirmed: false,
} ],
username: "johndoe",

【问题讨论】:

    标签: firebase google-cloud-functions google-cloud-firestore


    【解决方案1】:

    看起来对我来说最好的解决方案是与朋友一起创建一个子集合,并用 person_id、confirmed 等填充它。用户集合仍然会有 Firstname、Lastname 等。

    Users (collection)
    "c7xXQC5cEq5JyWyED8rX" (document)
    Friends (collection)
    "FadcjWG0GpDgkFujGWaa" (document)
    person_id: string -> Users -> document id
    confirmed: boolean
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多