【发布时间】:2018-06-06 02:20:15
【问题描述】:
在 Firebase 函数中检索我朋友的名字和姓氏的最佳方法是什么?我尝试了几种方法,但都不起作用。
- 用户集合。
- Persons_id 是自动生成的文档 ID。
- Friends 是一个带有 person_id 的对象数组。
- 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