Reputation: 45
I've read all the answers on similar questions, but the issues and solutions are different to what I'm experiencing, for example trying to query a deleted document, or having a property instead of a sub-collection.
Here is an image of my database:
I'm trying to get a count where all DrilledDepthTolerance.toleranceState is equal to "notMeasured".
I've run the query and setup the index in FireStore by following the link in the error message. It has set up the following in the Single field index, under Exemptions:
I think that this could be the problem - the documentation seems to always describe the index being added under the composite index, and this is created under the single field?
Here is my code (sorry, it's in c#):
try
{
var collectionRGroupRef = db.CollectionGroup("DrilledDepthTolerance");
Query query = collectionRGroupRef.WhereEqualTo("toleranceState", "notMeasured");
QuerySnapshot querySnapshot = await query.GetSnapshotAsync();
return querySnapshot;
}
catch (Exception e)
{
return null;
}
It returns a document count of zero.
The database has a document matching the query criteria.
I've has a look at the samples and the setup of my database seems to match the required setup from the samples. From the Firestore document, the data I would be querying in my database would be the same as searching for sub-collections where the first name = "Ada" in this example:
https://firebase.google.com/docs/firestore/manage-data/structure-data
I would really appreciate some pointers on where I am going wrong.
Upvotes: 1
Views: 506
Reputation: 317750
Your code is querying collections called "DrilledDepthTolerance":
var collectionRGroupRef = db.CollectionGroup("DrilledDepthTolerance");
As far as I can see, you don't have any collections with that name. You're showing a single document with a field called "DrilledDepthTolerance", which is a map with other fields in it.
Your collection is actually named "holes":
var collectionRGroupRef = db.CollectionGroup("holes");
You can query for the value of embedded toleranceState field like this:
Query query = collectionRGroupRef
.WhereEqualTo("DrilledDepthTolerance.toleranceState", "notMeasured");
Upvotes: 3