Race condition while updating single document multiple times

We are using spring data jpa and mongodb.
There is document A with two line item objects. Each line item has unique id. We consume messages from kafka topic at line item level and update the attributes in each line item.
In this situation we are seeing race condition and always second line item attributes are updated, but first line item attributes is not updated.

Object structure:

Document: {
id : 1234
line items: [
line_item1: {
id: ‘line_111’
received: false
}
line_item2: {
id: ‘line_222’,
received: false
}
]
}

line_item1 comes first from the topic and does findById(1234) and should update received = true for line_item1.
line_item2 comes next from the topic and does findById(1234) and should update received = true line_item2.

But actually this is not happening, line_item1 is never updated and received = false always and line_item2 received = true.

Most likely the issue is with your update code.

You probably overwrite line_item1 with it old value with your update for line_item2.

You will need to share your code so that we can help.

But before posting more code or documents, please read Formatting code and log snippets in posts.