4 ms·
> q.Update(document.ref, { data: { hits: document.data.hits + 1, ... Does FaunaDB have an "atomic increment" a la Firestore? Knowing nothing about FaunaDB, I s
by schemescape 6y ago
> q.Update(document.ref, { data: { hits: document.data.hits + 1, ...
Does FaunaDB have an "atomic increment" a la Firestore? Knowing nothing about FaunaDB, I suspect this code in the blog post has the potential to "lose" hits that come in at roughly the same time...
- quotemstr 6y agoFaunaDB appears to have some kind of transaction support[1], so atomic updates of the sort you mention seem feasible. That said, I'm a huge SQL partisan, and I'd much rather talk to a SQL database than this custom thing. https://docs.fauna.com/fauna/current/concepts/isolation_levels https://docs.fauna.com/fauna/current/concepts/isolation_leve...
- tyingq 6y agoI did find an example of an atomic increment in Faunadb. Sometimes SQL is easier :) : Update( Ref( Collection('topics'), '254119747652682260' ), { data: { clickCount: Add( Select( ['data','clickCount'], Get( Ref( Collection('topics'), '254119747652682260' ) ) ), 1 ) } } )