C# driver startsWith in Linq query creates regexp with s option causing slow queries

858 views
Skip to first unread message

Søren Bramer Schmidt

unread,
Aug 3, 2013, 10:44:26 AM8/3/13
to mongod...@googlegroups.com
When you create a LINQ query like 

collection.Linq<>().where(x => x.property.startsWith("something"))

the driver generates regular expressions with the s option

{ property: /^something/s }

This is a problem because it causes MongoDB to do a full table scan as documented in this issue https://jira.mongodb.org/browse/SERVER-9035


Is it possible to configure the C# driver to not use the s option for regular expressions?

craiggwilson

unread,
Aug 3, 2013, 11:29:09 AM8/3/13
to mongod...@googlegroups.com
No, there is no way to turn this off other than modifying the source code.  when you are using regular expressions like this, we are writing out the regular expression that most closely matches your string.  I guess you could argue that you don't need /s all the time, but we really don't know when to use it and when not to.  Since this is a server problem, we'll likely leave the driver alone.

The way to fix this is to use a new Regex("^something") and make sure the SingleLine flag is not specified.  That way, the s won't be included.

Søren Bramer Schmidt

unread,
Aug 3, 2013, 12:20:07 PM8/3/13
to mongod...@googlegroups.com
Thanks Craig

receiving a fast response like that is amazing. Ill go vote on the server issue then.
Reply all
Reply to author
Forward
0 new messages