【发布时间】:2021-01-11 02:21:29
【问题描述】:
我正在尝试使用此节点 js 代码在 firestore 中设置一些数据:
const db = admin.firestore();
const allDB = db.collection("like").doc("all").collection("movies");
const s1 = db.collection("like").doc("all");
await s1.set({
type: ["all"],
});
在控制台中运行文件:node file.js
给我这个错误:
await s1.set({
^^^^^
SyntaxError: await is only valid in async function
at wrapSafe (internal/modules/cjs/loader.js:1053:16)
at Module._compile (internal/modules/cjs/loader.js:1101:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
如何解决这个问题
【问题讨论】:
-
以后,我建议在发布您的问题之前先进行网络搜索。这个问题已经被问过很多次了,您可以通过查看现有答案来获得帮助。
标签: node.js google-cloud-firestore