How to use MongoRegex (MongoDB C# Driver)

Posted by Hery on Stack Overflow See other posts from Stack Overflow or by Hery
Published on 2010-03-26T23:30:03Z Indexed on 2010/03/26 23:33 UTC
Read the original article Hit count: 465

Filed under:
|

Has anyone have any idea how to use MongoRegex for the document search?

I attempted this, but returns nothing back:

var spec = new Document();
spec.Add("Name", new MongoRegex("/" + searchKey + "*/", "i"));
collection.Find(spec)

Wondering why it doesn't work, I tried to execute following command from the console:

db.things.find({"Name":/john*/i}) /* WORKS */
db.things.find({"Name":"/john*/i"}) /* DOESN'T WORK */

Is that possible that the driver applies double quotation to the regex?

Thanks..

© Stack Overflow or respective owner

Related posts about mongodb

Related posts about mongodb-csharp