c# - 如何修复 RpcException:项目 new-project 不存在或不包含活动的 Cloud Datastore 或 Cloud Firestore 数据库
问题描述
使用.net core 2+ web api,我试图在firestore中创建一个集合并向其中添加文档。初始化 Cloud Firestore 工作正常,并通过返回包含已初始化项目 ID 的 OK 结果来证明。但是当我要创建一个集合并向其中添加一个文档时,我开始收到一条错误消息,指出我的项目不存在。
为了能够通过我的 api 与 firestore 通信,我从 NuGet 安装了 google 的 Google.Cloud.Firestore (1.0.0-beta20)。另外,我已经在 firebase 控制台中设置了 new-project(new-project 是 firebase 项目名称)。我的环境中也已经设置了新项目的服务密钥——通过向 GOOGLE_APPLICATION_CREDENTIALS 提供服务密钥路径的路径。最初,我遇到了“名称解析失败”错误,但在我的环境中设置 GRPC_DNS_RESOLVER=native 后该错误就消失了。
这是我与firestore的沟通方式。
var db = FirestoreDb.Create("new-project");
var collectionReference = db.Collection("users");
var docRef1 = collectionReference.Document("alovelace");
var user1 = new Dictionary<string, object>
{
{ "First", "Ada" },
{ "Last", "Lovelace" },
{ "Born", 1815 }
};
await docRef1.SetAsync(user1);
错误信息是
RpcException: Status(StatusCode=NotFound, Detail="The project new-project does not exist or it does not contain an active Cloud Datastore or Cloud Firestore database. Please visit http://console.cloud.google.com to create a project or https://console.cloud.google.com/datastore/setup?project=new-project to add a Cloud Datastore or Cloud Firestore database. Note that Cloud Datastore or Cloud Firestore always have an associated App Engine app and this app must not be disabled.")
堆栈跟踪是
Google.Api.Gax.Grpc.ApiCallRetryExtensions+<>c__DisplayClass0_0<TRequest, TResponse>+<<WithRetry>b__0>d.MoveNext()
Google.Cloud.Firestore.WriteBatch.CommitAsync(ByteString transactionId, CancellationToken cancellationToken) in WriteBatch.cs
Google.Cloud.Firestore.DocumentReference.SetAsync(object documentData, SetOptions options, CancellationToken cancellationToken) in DocumentReference.cs
DashApi.Controllers.ValuesController.Get() in ValuesController.cs
var user1 = new Dictionary<string, object>
{
{ "First", "Ada" },
{ "Last", "Lovelace" },
{ "Born", 1815 }
};
await docRef1.SetAsync(user1); //THIS IS WHAT TRIGGERS THE ERROR.
lambda_method(Closure , object )
Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable+Awaiter.GetResult()
Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor+AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
System.Threading.Tasks.ValueTask<TResult>.get_Result()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
我已经关注了文档,并希望在该集合下有一个用户集合和 alovelace 文档,而不是一个错误。
解决方案
推荐阅读
- c++ - 如何使用 CMake 正确构建和构建此 C++ 项目
- swiftui - SwiftUI 放大手势()延迟
- r - 如何在 stringdist 连接中锁定“by”列的第一个数字?
- javascript - 如何使用带有嵌入的 message.react - Discord.js V13
- r - 根据自己的`draw_panel()`为新的`ggproto`适配`draw_key()`
- excel - 在 OLAP 数据模型数据透视表的报表过滤器中禁用(全部)选项
- django-templates - 在 Django 模板中使用引导表粘性标题扩展
- r - R函数为数据集的子集创建单个回归线
- javascript - 使用 MediaRecorder API 动态控制将实时视频上传到 S3 分段的块大小
- ios - 如何在 iOS 扩展中设置 Flutter 平台频道(播客上传扩展)