massimilianokraus / MongoDB.DeepUpdater.CSharp

An extension of the official framework of MongoDB for C#
MIT License
6 stars 1 forks source link

Chaining without initial document #2

Open topojonas opened 3 years ago

topojonas commented 3 years ago

Hi Massimiliano, this library is a really helpful extension and makes working with nested arrays a lot easier and fun, thanks for that.

I was wondering if it is possible to add a .Deep() without any parameters using the generic type? A lot of our Updates are specifying the document via Filter without actually having the document fetched beforehand.

Thanks for your help and work so far!

massimilianokraus commented 3 years ago

Hi @topojonas , thank you for the appreciation. I'm planning on revisiting this library in the second half of October. I have had an overwhelming quantity of work ongoing these months. Meantime, could you please provide a code example of a use case with the modification you're asking for? Just so I can understand well how I could improve this library further.

topojonas commented 3 years ago

I was thinking along the lines of following, where I have not fetched the Entity yet but want to update a nested array without fetching the Entity beforehand:

var filterDefinition = Builders<Entity>.Filter.Where(e => e.Id == entityId);
var updateDefinition = Builders<Entity>.Update
          .Deep<Entity>()
          .SelectArray(e => e.children)
          .Where(c => c.Id == childId)
          .SelectArray(c => c.someList)
          .AddToSet(value);
var result = await UpdateAsync(filterDefinition, updateDefinition);

Theoretically the generic on .Deep<>() might not even be needed because it could be inferred from the Update Builder.

abrasat commented 2 years ago

Same opinion here, the feature requested by @topojonas would be a really important improvement. Thanks for the great library @massimilianokraus

P.S. The possibility to update the value of some property in an array item from a deeply nested array would be also a very useful improvement of this great library.

massimilianokraus commented 2 years ago

Given the great workload I'm facing these months, I have not been able to improve my library. However, I'll have some time during the winter holidays, so in a few weeks. Thank you for your patience, I appreciate your feedback very much.

larsbloch commented 2 years ago

This library is awesome. Great work ! 5 years old and still fixes an issue people are asking questions on to this day.

I agree with topojonas. This change would complete the project. Maybe someone in this thread has enough insights into mongodb to make a pull request ?