Hello, I'm struggling with such a problem.
I have a model, say Product, and this model has a collection of Description objects.
public class Product
{
public List<Description> Descriptions { get; set; }
}
The external service sends notifications that trigger the update of a specific Description of the Product object.
The problem is, that these notifications are sent in groups, about 7 notifications at one go (by one specific description for each country). So when I start to process these messages, I start to do it simultaniously, and I suppose that multiple writes overwrites each other because the result is rather unpredictable - sometimes it works, sometimes the descriptions remain unchnaged.
Here is my code:
_session.Advanced.Defer(new PatchCommandData(
id: product.Id,
changeVector: null,
patch: new PatchRequest
{
Script = @"this.Descriptions = this.Descriptions.filter(desc=> desc.CountryCode.toLowerCase() != args.CountryCode.toLowerCase())",
Values =
{
{"CountryCode", description.CountryCode},
{"LangCode", description.LangCode}
}
},
patchIfMissing: null));
if (description != null)
{
_session.Advanced.Patch<Product, Description>(product, x => x.Descriptions, c => c.Add(description));
}
_session.SaveChanges();
The JS script means "leave descriptions for any other country than one that is being processed right now". And then goes patch request, if necessary.
Long story short - I'd like to know how should I update nested collection objects in this case?
I thought that patches stuff works like requests that are placed in kind of a queue on raven server and are processed in strict order, but it doesn't seem like that.
Thanks.
PS I've also had an idea to change the script to take index of a Description entry, remove it with JS 'splice', and then insert the new one, but since the request execution is not strictly ordered, the indexes might bias and this makes no sense.