【发布时间】:2020-05-20 06:50:08
【问题描述】:
尝试根据 DocumentID 列表从集合中获取少量文档,但无法使用 WhereIn 和 FieldPath 进行以下操作。 Nuget 版本 Google.Cloud.Firestore v1.1.0
public async Task<IEnumerable<T>> GetByDocumentIdWhereIn(IEnumerable<string> documentIds)
{
CollectionReference ref= FirestoreDb.Collection(_collectionName);
Query query = ref.WhereIn(FieldPath.DocumentId, documentIds);
QuerySnapshot querySnapshot = await query.GetSnapshotAsync();
...
}
当使用几个 documentIds 执行时,我收到以下错误。
RpcException: Status(StatusCode=InvalidArgument, Detail="__key__ filter value must be a Key")
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Grpc.Core.Internal.ClientResponseStream+<MoveNext>d__5.MoveNext() in ClientResponseStream.cs
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Linq.AsyncEnumerable+<ForEachAsync_>d__174.MoveNext() in ForEach.cs
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Google.Cloud.Firestore.Query+<GetSnapshotAsync>d__54.MoveNext() in Query.cs
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
有什么想法吗?
【问题讨论】:
-
嗯。我不知道这是否是仅限客户端的限制,或者即使我们允许它在客户端它是否会在服务器端失败。会调查。我创建了github.com/googleapis/google-cloud-dotnet/issues/4981 来跟踪它。
-
顺便说一句,除了一次性获取一堆文档之外,您还需要其他功能吗?
FirestoreDb.GetAllSnapshotsAsync可能是一种更简单的方法。 -
啊 - 我误读了异常。这是已经是服务器端的限制。我需要询问 Firestore 团队。
-
如果我理解您提到的服务器端/客户端术语,C# 库被视为从底层 api(服务器端)获取数据的客户端库?而且因为这是潜在的 api 问题,所以目前没有明显的解决方法?
-
昨天我发布了 Google.Cloud.Firestore 2.1.0,它应该可以让你的原始代码工作。
标签: c# google-cloud-platform google-cloud-firestore