如何修复RpcException:项目new-project不存在或不包含活动的Cloud Datastore或Cloud Firestore数据库

时间:2019-06-10 02:13:06

标签: c# google-cloud-firestore asp.net-core-webapi

我正在使用.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文档,而不是一个错误。

0 个答案:

没有答案