I am trying to match the fields of originalEmail
with a mail address like [email protected], but no matter, case sensitive means to also find [email protected] fields.
public ObjectId? GetEntityIdByOriginalEmail(string originalEmail)
{
FilterDefinition<Entity> filter = "{ x : { $regex : /" + originalEmail + "//i } }";
var entity = _entitiesStorage.GetSingleOrDefault(filter);
if (entity == null)
return null;
return entity._id;
}
This didn't work for me. Why?
You can use Builders.Filter.Regex
.
public async Task<Entity> GetEntityIdByOriginalEmail(string originalEmail)
{
var collection = GetCollection();
var filter = Builders<Entity>.Filter.Regex("x", new BsonRegularExpression(originalEmail, "i"));
return await collection.Find(filter).FirstOrDefaultAsync();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With