samuk190 / localbase

A Firebase-Style Database ... Offline!
649 stars 83 forks source link

update doc, if not exist create {merge: true} #43

Closed rendomnet closed 4 months ago

rendomnet commented 3 years ago

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})

lindsaykwardell commented 3 years 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.

zakaria-chahboun commented 3 years ago

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

samuk190 commented 4 months ago

This issue is old, and the solution provided by @zakaria-chahboun was added to docs branch main