You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From the docs it seems like I need to fetch the document using findById(), update this record, and then pass that to update(). Is that the only way to do this ? It seems like a big limitation performancewise :/
Happy to help if needed :)
The text was updated successfully, but these errors were encountered:
This isn't just an issue performance wise but can also cause a data consistency issue when different fields of a single document are being updated concurrently. Consider a document like {id:'xxxx', a:1, b:2}. If say there are two calls in parallel, one which updates 'a' to 3 and another updating 'b' to 4. If each gets the data from firestore before either has updated the data, then updates would like - Update a to 3 -> {id:'xxxx', a:3, b:2} Update b to 4 -> {id:'xxxx', a:1, b:4}
Now whatever the order of updates, it would result in wrong final state. This can of course be handled by writing firestore rules which don't allow such updates by keeping an 'update_time' field along with data but it's an overhead. The easiest way would be to allow partial updates, like firestore does.
The ideal implementetation would add a flag at initialization updateStrategy: 'replace', 'merge' where replace would be the default and the repository update method would also allow a config object (as a second parameter) to allow local override of the setting.
Hi there,
I'm having troubles figuring out how to update a document without passing a complete object to the
update()
function.Let's say I have a User model like so
// user_model.ts
later in my code I would like to be able to update lets say this user's display_name based only on its id.
From the docs it seems like I need to fetch the document using
findById()
, update this record, and then pass that toupdate()
. Is that the only way to do this ? It seems like a big limitation performancewise :/Happy to help if needed :)
The text was updated successfully, but these errors were encountered: