Cloud firestore WhereIn 方法在 .Net 中不起作用

Cloud firestore WhereIn method not working in .Net

我在 .net core 中使用 google.cloud.firestore 包,我想查询在提供的值列表中存在特定字段值的文档(如 IN 命令sql)。我遇到了 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:\a\s\Ix.NET\Source\System.Interactive.Async\ForEach.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:\Docer\webapp- 
FireStore-Branch\Docer.DAL\Repositories\Document\DocumentRepository.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:\Docer\webapp-FireStore- 
Branch\Docer.BLL.Doc\Document\DocumentBusiness.cs:line 84

感谢任何帮助,谢谢。

感谢 Jon,问题似乎出在我使用的旧版 firestore 模拟器上。更新模拟器后,一切正常

这对我有用。你可以跟着教程(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();