小编Cri*_*zúa的帖子

如何知道firestore python中是否存在文档?

我正在使用 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

谢谢

python-3.x google-cloud-firestore

9
推荐指数
2
解决办法
6632
查看次数

找不到模块“fs”或其相应的类型声明

我无法让打字稿识别“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)

fs typescript

5
推荐指数
1
解决办法
7700
查看次数

使用在函数内部创建的实例吗?

我正在尝试创建一个创建类的函数,并将这些类附加到列表中.

当我运行该程序时:我收到以下错误:

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)

python global class instances

2
推荐指数
1
解决办法
98
查看次数