Closed rendomnet closed 4 months ago
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
This issue is old, and the solution provided by @zakaria-chahboun was added to docs branch main
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})