How do I add or remove a value in an array in a firestore document?

What’s the best way to add or remove values in a firestore array?
The official Firestore API works like this. Is there a way to do the same when you update a document in retool?

// Atomically add a new region to the "regions" array field.
washingtonRef.update({
    regions: firebase.firestore.FieldValue.arrayUnion("greater_virginia")
});

// Atomically remove a region from the "regions" array field.
washingtonRef.update({
    regions: firebase.firestore.FieldValue.arrayRemove("east_coast")
}); 

Thanks

Not sure if this can be done in JS queries here at retool, I honestly handle this in cloud funcs; plus I prefer to keep MOST of the DB related code in cloud funcs anyway, instead if trying to do too much locally in retool. My 2 cents. Cheers

Hey @cdedreuille! We don’t have native support for this quite yet, so your best bet is to pass a fully updated array in your query. So basically take the current value of the array, push new values to it via JS, and then pass that updated array to overwrite the existing one. Does that make sense?

(We’re working on building a raw query editor so you’ll be able to access the SDK directly!)

Thanks for the explanation. That’s what I’m doing right now but I’m glad to see it’s in the roadmap.

1 Like

Stay tuned :slight_smile:

1 Like