Firebase 模拟器从 2 个实时数据库开始?

Nor*_*ldt 9 firebase firebase-tools firebase-realtime-database

启动模拟器时,我在实时数据库模拟器中看到 2 个数据库。一个与<project id>另一个<project id>-default-rtdb

在此输入图像描述

有人可以解释或参考一些文档来解释为什么会这样吗?


这是我的设置文件

firebase.json

{
  "database": {
    "rules": "database.rules.json"
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ],
    "source": "functions"
  },
  "emulators": {
    "auth": {
      "port": 9099
    },
    "functions": {
      "port": 5001
    },
    "database": {
      "port": 9000
    },
    "pubsub": {
      "port": 8085
    },
    "ui": {
      "enabled": true
    }
  }
}

Run Code Online (Sandbox Code Playgroud)

函数/package.json

{
  "name": "functions",
  "scripts": {
    "lint": "eslint --ext .js,.ts .",
    "build": "tsc",
    "serve": "npm run build && firebase emulators:start --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "14"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "^9.8.0",
    "firebase-functions": "^3.14.1"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^3.9.1",
    "@typescript-eslint/parser": "^3.8.0",
    "eslint": "^7.6.0",
    "eslint-config-google": "^0.14.0",
    "eslint-plugin-import": "^2.22.0",
    "firebase-functions-test": "^0.2.0",
    "typescript": "^3.8.0"
  },
  "private": true
}

Run Code Online (Sandbox Code Playgroud)

Wik*_*own 1

所以我才明白了。将一个"database"部分添加到文件的顶层firebase.json会使模拟器创建 2 个数据库。此外,如果项目名称以.firebasercdemo 开头,并且"database"文件的顶层添加了一个部分firebase.json,那么总共将Realtime Database创建 3 个 s。

因此,有一个firebase.json如下所示的文件:

{ "database": {
    "rules": "database.rules.json"
  },
  "functions": [
    {
      "source": "functions",
      "codebase": "default",
      "ignore": [
        "node_modules",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ]
    }
  ],
  "emulators": {
    "auth": {
      "port": 9099
    },
    "database": {
      "port": 9000
    },
    "ui": {
      "enabled": true
    },
    "singleProjectMode": true
  }
}
Run Code Online (Sandbox Code Playgroud)

和一个.firebaserc如下所示的文件:

{
  "projects": {
    "default": "demo-MyProject-development"
  }
}
Run Code Online (Sandbox Code Playgroud)

结果创建了 3 个数据库。

我决定不将规则文件添加到我的文件中firebase.json(从而从文件中删除该"database"部分)并将规则手动写入浏览器中。

我的文件现在看起来像这样:

firebase.json

{ 
  "functions": [
    {
      "source": "functions",
      "codebase": "default",
      "ignore": [
        "node_modules",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ]
    }
  ],
  "emulators": {
    "auth": {
      "port": 9099
    },
    "database": {
      "port": 9000
    },
    "ui": {
      "enabled": true
    },
    "singleProjectMode": true
  }
}

Run Code Online (Sandbox Code Playgroud)

.firebaserc

{
  "projects": {
    "default": "MyProject-development"
  }
}

Run Code Online (Sandbox Code Playgroud)