I'm trying to locate a user with a Username and a Password that match. I have an office collection that each office document contains MANY users
var builder = Builders<MnOffice>.Filter;
var filter = builder.AnyEq(o => o.Users, new OfficeUser()
{
Username = username,
Password = password
});
var office = await Offices.Find(filter).FirstOrDefaultAsync().ConfigureAwait(false);
return office;
the above query returns null. although it should get the result back. the OfficeUser class has three properties, Username, Password, and Name. Mongo forces me that all three properties will match in the query, all I want is to have 2 properties matching (usename and password) in order to get the result back, How can accomplish that? no good documentation for that.
Thanks!
var filter = builder.ElemMatch(o => o.Users, user => user.Username == username && user.Password == password);
Solved that using ElemMatch, but still dont understand the logic behind the first attempt.