Best practice for querying then updating to a model with lb

22 views
Skip to first unread message

xiaolu liu

unread,
Aug 4, 2017, 7:45:04 AM8/4/17
to LoopbackJS

Hi guys,
Thanks for providing such amazing framework, however, I am not sure how to handle the following cases with loopback:

  1. I have a 'idInjected' model, so the primary id is unknown. I have to findOne with a condition first then save or create the instance according to the finding result.
  2. I know the primary Id, but I don't know the current field value, so I have to findById first then do some caculation based on the current value. e.g. page.viewed += 1; page.save();

However, we may face a race condition when some concurrent requests hit, due to find/update are async methods.

Do we have locker or something for loopback to handle these cases. Any suggestions are welcome!

Reply all
Reply to author
Forward
0 new messages