public async Task AddHouseholdToUser(User user, ObjectId householdId) { if (!(await Households.FindAsync(x => x.Id == householdId)).Any()) { throw new ApplicationException("Household doesn't exist."); } await Users.FindOneAndUpdateAsync(x => x.Id == user.Id, Builders <User> .Update.AddToSet(x => x.Households, householdId)); Logger.LogInformation("Household adds to user", user, householdId); }
public async Task <Household[]> FindHouseholdsById(IEnumerable <ObjectId> households) { var result = await Households.FindAsync(x => households.Contains(x.Id)); return(result.ToList().ToArray()); }