How to query nested object in Firestore?

Viewed 96

I have a Firestore document with some fields and nested fields.

{
    "id": "123",
    "user": {
        "id": "ABC"
    }
}

How do I query by "user.id" in Objective-C? I tried this but it doesn't return any documents.

FIRQuery *collectionQuery = [collection queryWhereField:@"user.id" isEqualTo:"ABC"];
[collectionQuery getDocumentsWithCompletion:^(FIRQuerySnapshot * _Nullable snapshot, NSError * _Nullable error) {

}];

This works fine for reading the first level "id" field but I'm not able to read nested fields in the document.

FIRQuery *collectionQuery = [collection queryWhereField:@"id" isEqualTo:"123"];
[collectionQuery getDocumentsWithCompletion:^(FIRQuerySnapshot * _Nullable snapshot, NSError * _Nullable error) {

}];
0 Answers
Related