Reputation: 331
I've tried to use the same query with flutter and node.js. On flutter it works - but on node.js the API tells that a index is required. Now I've no idea how to solve my problem on node.js.
Firestore collection:
{
name: "NameA",
members: {
"A7bn2": { role: "owner", "approved": true },
"b1aw1": { role: "owner", "approved": true },
}
}
doesn't work :-(
return this.firestore.collection("projects")
.where(`members.${this.auth.currentUser.uid}.role`,
'==', 'owner')
log message:
Uncaught Error in snapshot listener: FirebaseError: The query requires an index. You can create it here
the suggested index (with the uid)
members.I21HsjQCL7sDgb34CgYi1.role Ascending name Ascending
query works with dart/flutter
.where('members.${_auth.currentUser!.uid.toString()}.role',
isEqualTo: 'owner')
.snapshots()
Upvotes: 1
Views: 124
Reputation: 4897
Answer found in comments. Add a compound index if you need to sort or search by more than one field.
Error message has a link to where you can create the required index. Or add a firestore.indexes.json
file and use firebase
cli to deploy indexes from that file.
Upvotes: 1