我在.net core
中使用google.cloud.firestore
包,我想查询具有特定字段值的文档,该字段值存在于提供的值列表中(如sql中的IN
命令(。我遇到了WhereIn
方法,但总是遇到一个异常。过去几个小时我一直在努力,但没有成功
这是代码:
public async Task<List<Document>> GetListByAccountRef(List<string> accountRefs)
{
var docRef = _Firestore.Collection("documents").WhereIn("AccountRef", accountRefs);
var docsQuery = await docRef.GetSnapshotAsync();
var docs = docsQuery.Select(d => d.ConvertTo<Document>()).ToList();
return docs;
}
我在第二行得到一个异常:var docsQuery = await docRef.GetSnapshotAsync();
这是错误消息:
Status(StatusCode=InvalidArgument, Detail="Unknown FieldFilter operator.")
这里是堆叠竞赛:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Grpc.Core.Internal.ClientResponseStream`2.<MoveNext>d__5.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Linq.AsyncEnumerable.<ForEachAsync_>d__174`1.MoveNext() in
D:a1sIx.NETSourceSystem.Interactive.AsyncForEach.cs:line 141
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Cloud.Firestore.Query.<GetSnapshotAsync>d__54.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Docer.DAL.Repositories.DocumentRepository.<GetListByAccountRef>d__7.MoveNext() in E:Docerwebapp-
FireStore-BranchDocer.DALRepositoriesDocumentDocumentRepository.cs:line 84
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Docer.BLL.Doc.DocumentBusiness.<GetUserDocuments>d__10.MoveNext() in E:Docerwebapp-FireStore-
BranchDocer.BLL.DocDocumentDocumentBusiness.cs:line 84
感谢您的帮助。
这对我很有用(https://pieterdlinde.medium.com/netcore-and-cloud-firestore-94628943eb3c)
List<Cities> cities = new List<Cities>()
{
new Cities()
{
CityName="tests"
}
};
Query employeeQuery = fireStoreDb.Collection(nameof(Employee)).WhereIn("City", cities);
QuerySnapshot employeeQuerySnapshot = await employeeQuery.GetSnapshotAsync();
多亏了Jon,问题似乎来自我使用的旧版本的firestore模拟器。更新模拟器后,它运行良好。