在Firebase功能中检索朋友的名字和姓氏的最佳方法是什么?我尝试了几种方法,但它没有用。
我正在使用文档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",
答案 0 :(得分:0)
对我来说,最好的解决方案是与朋友一起创建子集合,并使用person_id,确认等填充该集合。用户集合仍然具有名字,姓氏等。
Users (collection)
"c7xXQC5cEq5JyWyED8rX" (document)
Friends (collection)
"FadcjWG0GpDgkFujGWaa" (document)
person_id: string -> Users -> document id
confirmed: boolean