Search code examples
c#.net-coregoogle-cloud-firestorefirebase-cli

Cloud firestore WhereIn method not working in .Net


I am using google.cloud.firestore package in .net core and I want to query the documents that have a specific field value existing in a provided list of values (like the IN command in sql). I came across the WhereIn method but I keep getting an exception. I have been trying for the last few hours but no success!
Here is the code:

   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;
    }

I get an exception on the second line:
var docsQuery = await docRef.GetSnapshotAsync();

This is the error message:

Status(StatusCode=InvalidArgument, Detail="Unknown FieldFilter operator.")

And here is the stacktrace:

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\1\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

Any help is appreciated, thanks.


Solution

  • Thanks to Jon, the problem appeared to be from the old version of the firestore emulator that I was using. After updating the emulator, it's working fine.