Reputation: 47
I tried to find all records in collection by specific array element(underlined in blue):
This is my code:
FilterDefinition<string> queryTemplate = Builders<string>.Filter.Eq(pr => pr, templateId);
return Database.GetCollection<AutoSave>(MongoDb.AutoSaveCollection)
.Find(Builders<AutoSave>.Filter.ElemMatch(x => x.Templates, queryTemplate)).ToList();
But it doesnt work.
Upvotes: 2
Views: 66
Reputation: 5669
give the following filter a try:
var filter = Builders<AutoSave>.Filter.Where(s => s.Templates.Contains(templateId));
var result = collection.Find(filter).ToList();
here's a test program
Upvotes: 1