0
運行時如何使用official drivers生成過濾器?我想要得到的聯繫人包含特定的用戶ID和可以過濾一些屬性(包含一些文本)通過MongoDB的多個過濾器C#驅動程序
當前代碼不與request.Filter > 1
工作:
private FilterDefinition<Contact> BuildFilter(NgTableRequest request, string userId)
{
var filters = new List<FilterDefinition<Contact>>
{
Builders<Contact>.Filter.Where(q => q.ContactUsers.Any(w => w.UserId == userId))
};
if (request.Filter != null && request.Filter.Any())
{
foreach (var reqFilter in request.Filter)
{
filters.Add(Builders<Contact>.Filter.Regex(reqFilter.Key, reqFilter.Value[0]));
}
}
var result = Builders<Contact>.Filter.And(filters);
return result;
}