Essayez ceci
var mongoClient = new MongoClient();
var collection = mongoClient.GetDatabase("test").GetCollection<Rootobject>("test");
ObjectId someId = new ObjectId("599e670f2720317af451db9e");
string someName = "Car 1";
var item = await collection.AsQueryable()
.Where(x => x.Id == someId)
.SelectMany(x => x.Cars)
.Where(x => x.Name == someName)
.FirstOrDefaultAsync();
Cela génère la requête d'agrégation ci-dessous :
{aggregate([{ "$match" : { "_id" : ObjectId("599e670f2720317af451db9e") } }, { "$unwind" : "$Cars" }, { "$project" : { "Cars" : "$Cars", "_id" : 0 } }, { "$match" : { "Cars.Name" : "Car 1" } }])}
qui crache les résultats suivants :
{ "Cars" : { "Name" : "Car 1", "Labels" : [ { "Label" : "Main", "Color" : "#F49973" } ] } }