Sunday, October 28, 2012

query Mongo using multiple criteria from C#

public List<UserAccounts> GetUserAccount(string email, string password)
{
   var server = MongoServer.Create("foo");
   var database = server.GetDatabase("bar");
   var allRecords = database.GetCollection<UserAccountDataTransferObject>("baz");
   var query = from user in allRecords.AsQueryable<UserAccountDataTransferObject>()
            where user.Email == email && user.Password == password
            select user;
   List<UserAccount> userAccounts = new List<UserAccount>() { };
   foreach (UserAccountDataTransferObject userAccount in query)
   {
      userAccounts.Add(new UserAccount(userAccount.Email, userAccount.Password,
            userAccount.Status));
   }
   return userAccounts;
}

No comments:

Post a Comment