Javascript 获取云函数中的文档值
我的云Firestore数据库如下所示:Javascript 获取云函数中的文档值,javascript,firebase,google-cloud-firestore,google-cloud-functions,Javascript,Firebase,Google Cloud Firestore,Google Cloud Functions,我的云Firestore数据库如下所示: users | |----id----(name,age) |----id----(name,age) |----id----(name,age) |----id----(name,age) |----id----(name,age) ... 我正在通过所有元素编写查询: db.collection('users').get() .then( (results) => {
users
|
|----id----(name,age)
|----id----(name,age)
|----id----(name,age)
|----id----(name,age)
|----id----(name,age)
...
我正在通过所有元素编写查询:
db.collection('users').get()
.then(
(results) => {
results.forEach((doc) => {
//how to get the id that represents this doc?
});
response.json();
}
)
.catch(function (error) {
console.error("Error getting user: ", error);
response.send(error)
});
我的问题很简单:变量doc表示一个id(包含一个带有名称和年龄的集合)。我怎样才能得到这个身份证?我可以从文档中检索它吗?这其实很简单。
doc
变量实际上是,您可以从其ID
属性获取其ID。因此:
db.collection('users').get()
.then(
(results) => {
results.forEach((doc) => {
console.log(doc.id);
});
}
)
.catch(function (error) {
console.error("Error getting user: ", error);
response.send(error)
});