I'm relatively new to Firebase and Firestore, I have created 2 Index in the firestore web app and seems like I also have to update the firestore.indexes.json on my IDE.
Base from the image above, is this the correct way of adding it on VSCODE? I'm just assuming it is.
{
"indexes": [
{
"collectionGroup": "timeinout",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "uid",
"order": "ASCENDING"
},
{
"fieldPath": "createdAt",
"order": "ASCENDING"
},
{
"fieldPath": "uid",
"order": "ASCENDING"
},
{
"fieldPath": "timein",
"order": "ASCENDING"
}
]
}
],
"fieldOverrides": []
}
CodePudding user response:
The index definition is almost there, but it will only create one index, across all four of those fields (one of which, uid, will be duplicated).
To create 2 indexes, you can put 2 entries in the indexes
array rather than putting all 4 fields into a single index entry:
{
"indexes": [
{
"collectionGroup": "timeinout",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "uid",
"order": "ASCENDING"
},
{
"fieldPath": "createdAt",
"order": "ASCENDING"
}
]
},
{
"collectionGroup": "timeinout",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "uid",
"order": "ASCENDING"
},
{
"fieldPath": "timein",
"order": "ASCENDING"
}
]
}
],
"fieldOverrides": []
}