I have User object:
{
"_id" : ObjectId("599e670f2720317af451db9e"),
"Cars" : [
{
"Name" : "Car 1",
"Labels" : [
{
"Label" : "Main",
"Color" : "#F49973"
}
]
},
{
"Name" : "Car 2",
"Labels" : [
{
"Label" : "Main",
"Color" : "#F49973"
},
{
"Label" : "Secondary",
"Color" : "#E2E2E2"
}
]
}
]
}
I want to find document by user id and car name, then select this car. I am trying to do this:
await _collection.AsQueryable().Where(u => u.Id == someId && u.Cars.Any(s => s.Name == someName))
.Select(u => u.Cars[-1])
.SingleOrDefaultAsync();
In result, I want to get single Car object, but, I get null. How to properly to do it?