我正在使用 google.cloud 的 firestore 库,有没有办法在不检索所有数据的情况下检查文档是否存在?我试过
fs.document("path/to/document").get().exists()
Run Code Online (Sandbox Code Playgroud)
但它返回 404 错误。(google.api_core.exceptions.NotFound)
然后我试过了
fs.document("path/to/document").exists()
Run Code Online (Sandbox Code Playgroud)
但“存在”不是来自 DocumentReference 的函数。
从源代码可以看出,exists() 是 DocumentSnapshot 类中的一个函数,函数 get() 应该返回一个 documentSnapshot。我不太确定我还能如何获得 DocumentSnapshot
谢谢
我无法让打字稿识别“fs”模块。我收到以下错误:
Error: src/app/components/drops/drops-map/drops-map.component.ts:9:29 - error TS2307: Cannot find module 'fs' or its corresponding type declarations.
9 import {readFileSync} from 'fs';
Run Code Online (Sandbox Code Playgroud)
我通过以下方式安装了定义:
npm i @types/node --save-dev
Run Code Online (Sandbox Code Playgroud)
我检查了 fs.d.ts 是否正确放置在 node_modules/@types/node 文件夹中
这是我的 tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"module": "es2020",
"lib": [
"es2018",
"dom"
],
"typeRoots": [
"node_modules/@types",
"node_modules/@types/node"
],
},
"angularCompilerOptions": {
"strictInjectionParameters": true, …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个创建类的函数,并将这些类附加到列表中.
当我运行该程序时:我收到以下错误:
NameError:未定义名称'jackie'
这意味着只能使用函数内部的实例.我怎样才能使它全球化?我试过global eval('jackie')但不起作用.
population =[]
class person():pass
def createdarwin(name):
global population
darwin=p.image.load('darwin.png')
vars()[name]=person(darwin)
population.append(name)
def main():
createdarwin('jackie')
for i in population:
eval(i).update()
Run Code Online (Sandbox Code Playgroud)