I am working on firestore and my firestore collection structure as below:
Users-> userId1 -> UserDetails -> User_Info -> JSON Data
Users-> userId2 -> UserDetails -> User_Info -> JSON Data
Users-> userId3 -> UserDetails -> User_Info -> JSON Data
Users-> userId4 -> UserDetails -> User_Info -> JSON Data
For better understanding, please have a look in below snapshot:
Now I need a firestore query to fetch the list of userIds who has isCardOrdered is true.
The result should be:
[
"userId1",
"userId2",
"userId3",
"userId4"
]
I am doing this, but I am not getting the correct result.
@Injectable()
export class UsersClient {
constructor(
@Inject(UsersClientDocument.collectionName)
private UsersCollection: CollectionReference<UsersClientDocument>,
) { }
async fetchByQuery(query) {
console.log('******************************');
const querySnapshot = await this.UsersCollection.where('cardInfo[0].isCardOrdered', '==', true).get();
querySnapshot.forEach((doc) => {
console.log(' **********fetchByQuery:',doc.id, ' => ', doc.data());
});
}
}
And I am calling this method like this:
const fireBaseUser: any = await this.UsersClient.fetchByQuery();
console.log('fireBaseUser:',fireBaseUser);
Request: Any help would be appreciated. Thanks
