reactjs 如何在Firebase实时数据库仿真器中解析多个projectID

uyhoqukh  于 2023-03-29  发布在  React
关注(0)|答案(1)|浏览(98)

我正在使用firebase模拟器数据库,当试图通过“editedAt”命令消息时,得到以下警告。

2023-03-24T18:21:33.576Z]  @firebase/database: FIREBASE WARNING: Using an unspecified index. 
Your data will be downloaded and filtered on the client. Consider adding ".indexOn": "editedAt" 
at /messages to your security rules for better performance.

我明白要解决这个警告,我需要使用editedAt索引

{
  "rules": {
    "messages": {
      ".indexOn": ["editedAt"]
    }
  }
}

然而,当我尝试在我的database.rules.json文件中使用时,它并没有解决警告。
1 -模拟器正在为错误的项目ID更新规则,它应该是learn-firestore-dev,但它正在更新learn-firestore-dev-default-rtdb

database: Change detected, updating rules for learn-firestore-dev-default-rtdb

2 -在database-debug.log中,我看到以下警告

16:36:28.771 [FirebaseWorkerPool-1-3] WARN com.firebase.core.persistence.backend.dummy.EmulatorMetadataPersistence 
- Multiple projectIds are not recommended in single project mode. Requested 
namespace learn-firestore-prod, but the emulator is configured for learn-firestore-prod-default-rtdb. To 
opt-out of single project mode add/set the single_project_mode: false property in 
the firebase.json emulators config.

3 -

我不知道我做了什么才在模拟器上获得learn-firestore-dev-default-rtdb。
下面是我的firebase配置:

{
  "database": {
    "rules": "database.rules.json"
  },  
  "storage": {
    "rules": "storage.rules.json"
  },
  "hosting": {
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  "emulators": {
    "auth": {
      "port": 9099
    },
    "functions": {
      "port": 5001
    },
    "firestore": {
      "port": 8080
    },
    "database": {
      "port": 9000
    },
    "storage": {
      "port": 9199
    },
    "ui": {
      "enabled": true
    },
    "singleProjectMode": true
  }
}

我使用的数据库URL如下

"http://localhost:9000/?ns=learn-firestore-dev"
2lpgd968

2lpgd9681#

我找到了一个解决方法,没有解决这个问题,但这是一个临时的修复方法。我只是将数据库URL更改为创建的一个firebase模拟器,即。

"http://localhost:9000/?ns=learn-firestore-dev-default-rtdb"

相关问题