4
votes

On my current project I'm using a loopback backend as the REST API. My question is actually quite simple, but I wasn't able to figure it out on my own.

On my client I have a bulk of message objects which are updated by the user - these can add up to 50-100 messages.

Now I want to update the items using the loopback backend. There are some default endpoints which support PUT or PATCH methods. However, as soon as I pass an array I receive an error message, complaining that the item with the id already exists.

It seems wrong to me to just fire up 100 HTTP-Requests just to update a bunch of items. Any suggestions?

For completeness - here the error message.

{
  "error": {
    "name": "Error",
    "status": 500,
    "message": "Failed with multiple errors, see `details` for more information.",
    "details": [
    {
        "code": 11000,
        "index": 0,
        "errmsg": "E11000 duplicate key error collection: xxx.Message index: _id_ dup key: { : ObjectId('588bc0afcf8d8c7b13ff44e2') }",
        "op": {
           // message object
        }
    }
}
1
Create a custom endpoint. I think the batch update is not possible with current default endpoints - Ebrahim Pasbani

1 Answers

0
votes

I would create a custom remote method that can receive all of your messages. Then on the server loopback will offer multiple options to update/insert in batch.

Disclaimer: Remote method is a notion in Loopback 3.x. I'm not sure what the 4.x equivalent is.