How to filter ObjectId by using regex in MongoDB C#/.NET Driver?

I implement match using BsonRegularExpression,
but It’s not work for fields that type is ObjectId or ISODate.

Below is my code:

var searchValue = "3a5f";
var expr = new BsonRegularExpression(new Regex(searchValue, RegexOptions.None));
var builder = Builders<BsonDocument>.Filter;
var filter = builder.Regex("_id", expr);
var result = context.Find(filter).ToList();

How can I do?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.