[英]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.