AFAIK there is no other way that querying all the related models and counting them. Of course you could also implement a counter for model A, where you would keep track of amount of related B -elements. This would be fairly straight forward with DDB streams for example ( every time a B is created or removed, a Lambda is invoked which would then update the counter on related A)
#✅ - GraphQL API - extract length of array field
8 messages · Page 1 of 1 (latest)
You could use Condition expressions to overcome that.
This peace of docs does touch on that subject: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html#WorkingWithItems.AtomicCounters
The basic building blocks of Amazon DynamoDB start with tables, items, and attributes. Learn how to work with these and basic CRUD operations to start building powerful and scalable applications.
Yeah 🙂
But in short with conditional updates you can make sure a certain value is what you expect it to be at the time of an update, so race conditions shouldn't be possible.
Indeed!
If you want to keep accurate track of the number, perhaps you would also want to use SQS queue. So that if the incrementing operation fails for one reason or another, you could leverage the DLQ (where failed events will eventually end up at) to process that again later.
But this would probably be overkill at this point for you 😄
✅ - GraphQL API - extract length of array field