samuk190 / localbase

A Firebase-Style Database ... Offline!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

rendomnet opened this issue · comments

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

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