localbase icon indicating copy to clipboard operation
localbase copied to clipboard

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

Open rendomnet opened this issue 3 years ago • 2 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})

rendomnet avatar Jun 15 '21 12:06 rendomnet

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.

lindsaykwardell avatar Jul 07 '21 14:07 lindsaykwardell

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

zakaria-chahboun avatar Oct 04 '21 16:10 zakaria-chahboun