Reputation: 485
How do I query in mongo all documents that contain a specific element?
public class House
{
public Room [] Rooms {get; set;}
}
public class Room
{
public string Name {get; set;}
}
I need to build a filter that filter all houses with "bathroom", because I want to set the price of the bathroom to X.
Upvotes: 1
Views: 93
Reputation: 10918
The following code should do you what you want:
var collection = database.GetCollection<House>("houses");
collection.Find(new FilterDefinitionBuilder<House>().ElemMatch(house => house.Rooms, room => room.Name == "bathroom"));
Upvotes: 3