简体   繁体   English

使用 Cloud Firestore 数据库 API 创建云 Firestore 数据库,其中“database_id”为“(默认)”不起作用

[英]using Cloud Firestore Database API to create cloud firestore database with`database_id` of '(default)' not working

I used Google.Apis.Firestore.v1 library to create a cloud firestore for my firebase project as follows, but when running my code I am getting an error related to the database naming I guess, and it has a regular expression format as shown in the error below, and how can I fix this issue?我使用 Google.Apis.Firestore.v1 库为我的 firebase 项目创建了一个云 firestore,如下所示,但是在运行我的代码时,我收到了一个与数据库命名相关的错误,我猜它有一个正则表达式格式,如下所示下面的错误,我该如何解决这个问题?

using Google.Apis.Firestore.v1;

private static FirestoreService _firestoreService;
public static void IntializeFirestoreAdmin() {
   GoogleCredential credential = GoogleCredential.GetApplicationDefault();
   if (CloudManager.Credential.IsCreateScopedRequired)
   {
       credential = CloudManager.Credential.CreateScoped(FirestoreService.Scope.CloudPlatform);
            }
       _firestoreService = new FirestoreService(
        new BaseClientService.Initializer()
        {                 
           HttpClientInitializer = credential,
           ApplicationName = CloudManager.ApplicationName

        });          
            

        }
 public static void AddCloudFirestore() {
       IntializeFirestoreAdmin();
       var mydata = new GoogleFirestoreAdminV1Database {
                LocationId = "nam5",
                Type = "FIRESTORE_NATIVE",
                Name = "projects/" + CloudManager.ProjectId + "/databases/(default)",
                
            };
      _firestoreService.Projects.Databases.Create(mydata, "projects/" + CloudManager.ProjectId).Execute();
}

Error:错误:

Unhandled exception. The service firestore has thrown an exception.
HttpStatusCode is BadRequest.
Google.Apis.Requests.RequestError
database_id should be 4-63 characters, and valid characters are /[a-z][0-9]-/ [400]
Errors [
    Message[database_id should be 4-63 characters, and valid characters are /[a-z][0-9]-/] Location[ - ] Reason[badRequest] Domain[global]
]

Google.GoogleApiException: The service firestore has thrown an exception. HttpStatusCode is BadRequest. database_id should be 4-63 characters, and valid characters are /[a-z][0-9]-/
   at Google.Apis.Requests.ClientServiceRequest`1.ParseResponse(HttpResponseMessage response)
   at Google.Apis.Requests.ClientServiceRequest`1.Execute()

If you go through the given method :如果你通过给定的方法

FirestoreService().Projects.Databases.Create it has parent as Parameter and databaseId as a Query parameter there is also a try this method section where you can verify your parameters are correct like for example: FirestoreService().Projects.Databases.Create它有parent作为参数和databaseId作为 Query 参数 还有一个 try this method 部分,您可以在其中验证您的参数是否正确,例如:

using Google.Apis.Firestore.v1;

private static FirestoreService _firestoreService;
public static void IntializeFirestoreAdmin() {
   GoogleCredential credential = GoogleCredential.GetApplicationDefault();
   if (CloudManager.Credential.IsCreateScopedRequired)
   {
       credential = CloudManager.Credential.CreateScoped(FirestoreService.Scope.CloudPlatform);
            }
       _firestoreService = new FirestoreService(
        new BaseClientService.Initializer()
        {                 
           HttpClientInitializer = credential,
           ApplicationName = CloudManager.ApplicationName

        });          
            

        }
 public static void AddCloudFirestore() {
       IntializeFirestoreAdmin();
       var mydata = new GoogleFirestoreAdminV1Database {
                LocationId = "nam5",
                Type = "FIRESTORE_NATIVE",
                Name = "projects/" + CloudManager.ProjectId + "/databases/my-database",
                
            };
      _firestoreService.Projects.Databases.Create(mydata, "projects/" + CloudManager.ProjectId).Execute();
}
var body = new GoogleFirestoreAdminV1Database
{
    Type = "FIRESTORE_NATIVE",
    LocationId = "nam5"
};
string parent = $"projects/{CloudManager.ProjectId}";
var request = _firestoreService.Projects.Databases.Create(body, parent);
request.DatabaseId = "(default)";
var response = request.Execute();

The issue was that I didn't add the databaseId as a query parameter.问题是我没有将 databaseId 添加为查询参数。 For more details go to this link https://groups.google.com/g/google-cloud-firestore-discuss/c/EQ-04MnPyLk有关详细信息,请访问此链接https://groups.google.com/g/google-cloud-firestore-discuss/c/EQ-04MnPyLk

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 flutter firestore 未在云 firestore 数据库中创建文档 - flutter firestore not creating a document in the cloud firestore database 使用 FastAPI 在全球范围内访问 Cloud Firestore 数据库 - Access cloud Firestore database globally with FastAPI 无法从 Cloud Firestore 数据库下载图像 - Cannot download image from Cloud Firestore database Firebase 云功能不更新 Firestore 数据库中的数据 - Firebase Cloud function not updating data in Firestore database Cloud Firestore 和 Firebase 实时数据库有什么区别? - What's the difference between Cloud Firestore and the Firebase Realtime Database? 如何使用 flutter 中的 JSONserializable 在 Cloud Firestore 数据库中设置嵌套字段 - How do I set up a nested field in a Cloud Firestore database using JSONserializable in flutter 查询文件 ID 的 firestore 数据库 - Query firestore database for document id 使用自定义子集合 ID 在 firestore 数据库中设置文档 - Setting a document in firestore database with a custom subcollection id 在使用 Firestore 数据库时使用 onComplete() 方法中的变量 - Using variable from onComplete() method while working with Firestore database 我想从 Cloud Firestore 数据库中获取纬度和经度以在 map Android Studio 上添加标记 - I want to get latitude and longitude from Cloud Firestore database to add markers on map Android Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM