Reputation: 439
I have data structure like in this image. I need to update boolean value from true to false.
This is my function to perform the update, but it's not working...
The worldIndex and levelIndex a numbers.
export const setLevelPassed = (worldIndex, levelIndex) => new Promise(async (resolve, reject) => {
try {
await firestore()
.collection(auth().currentUser.uid)
.doc('gameDetails')
.update(gameData[worldIndex].questions[levelIndex].isLocked = false);
resolve();
} catch (e) {
reject(e);
console.log('setLevelPassed', e);
}
});
I tried this way too , but it's not working:
export const setLevelPassed = (worldIndex, levelIndex) => new Promise(async (resolve, reject) => {
try {
await firestore()
.collection(auth().currentUser.uid)
.doc('gameDetails')
.update(`gameData[${worldIndex}].questions[${levelIndex}].isLocked`, false);
resolve();
} catch (e) {
reject(e);
console.log('setLevelPassed', e);
}
});
Upvotes: 0
Views: 184
Reputation: 314
To update a field in firebase cloud firestore you must write
.update({ field : value, field : value, ... })
export const setLevelPassed = (worldIndex, levelIndex) => new Promise(async (resolve, reject) => {
try {
await firestore()
.collection(auth().currentUser.uid)
.doc('gameDetails')
.update({gameData[worldIndex].questions[levelIndex].isLocked: false});
resolve();
} catch (e) {
reject(e);
console.log('setLevelPassed', e);
}
});
Upvotes: 1