I recently came across the below piece of code in our application
var updateDefinition = new UpdateDefinitionBuilder<OverviewProfile>()
.Set(a => a.Advisors[-1].IsCurrent, advisor.IsCurrent);
In the above code, Advisors
is a List
and UpdateDefinitionBuilder
is from MongoDB driver.
Could you please let me know the use of -1 in the index of the list?
Editing after the below comments/answers
The OverviewProfile
class is as below:
public class OverviewProfile: BaseInvestorProfile
{
//Other properties
public List<Advisor.View.Advisor> Advisors { get; set; }
public OverviewProfile(int id): base(id)
{
Advisors = new List<Advisor.View.Advisor>();
}
}
And this is this the working code. This code updates the data to the mongo db based on the condition. There are no other methods inside this class, just other properties.
This is one class, but the same usage is there for properties of multiple class, and even when we add a new List
property and check, it works fine.