pb4*_*now 3 node.js typescript google-cloud-functions google-cloud-firestore
首先,这对我没有帮助:属性映射不存在并且导入“rxjs”也不会
只是使用 typescript 与我的函数进行测试,并使用“async”和“await”关键字,由于某种原因,我在尝试使用地图时遇到错误,这是我的代码(顺便说一句,如果我使用“await”从 firestore 检索数据的方式不正确)如果有人纠正我,我将非常感激)-找不到很多使用 typescript/functions/firestore 的示例):
import * as functions from 'firebase-functions';
import * as admin from "firebase-admin";
admin.initializeApp(functions.config().firebase);
let db = admin.firestore();
export const helloWorld = functions.https.onRequest(
async (request, response) => {
try {
let t = await getEmployees()
response.send("yes");
} catch (e) {
response.send('no')
}
});
async function getEmployees(): Promise<any> {
try {
const f = await db.collection('companies').get().map(value => {
let id = value.id
return id;
})
} catch (e) {
return e;
}
}
Run Code Online (Sandbox Code Playgroud)
打字稿版本 2.8.3
包.json:
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^5.12.0",
"firebase-functions": "^1.0.1"
},
"devDependencies": {
"tslint": "^5.8.0",
"typescript": "2.8.3"
},
"private": true
}
Run Code Online (Sandbox Code Playgroud)
await将应用于 的结果map,您实际上是在调用:
const f = await (db.collection('companies').get().map(...))
Run Code Online (Sandbox Code Playgroud)
您想要调用mapwaiting 的结果get,并且应该添加括号来告诉编译器这就是您想要执行的操作。此外,您可能正在寻找docs快照上的属性(它返回查询的结果)
const f = (await db.collection('companies').get()).docs.map(...)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2038 次 |
| 最近记录: |