localbase
localbase copied to clipboard
update doc, if not exist create {merge: true}
Can we have something similar to {merge: true} in firebase. Right now when we try to update none existent doc there will be error.
In firebase we can do localdb.collection(collection).doc(id).set(data, {merge: true})
Just ran into this myself, it would be a great addition. Currently doing an if/else to read the doc then add if it doesn't exist.
This is my solution, Just use add
with your key
like this:
// my key is "qid"
await db.collection('questions').add({ qid, tid, choosen_answers, question_status }, qid);
That's will automatically overwrite the existing record