0

I have this query running natively ok, but throws an exception when running in .net

FilterDefinition<BsonDocument> filter = "{'$and':[ {'A':{$ne:'1'}},{'B': {$regex:/.*Ios.*/i}}]}";
collection.Find(filter);

via .net I get the exception: JSON reader expected a string but found '/.*Ios.*/i'.

I believe it is because the regex value is not wrapped with quotes.

Whats the deal here?

John Saunders
  • 159,224
  • 26
  • 237
  • 393
SexyMF
  • 9,829
  • 31
  • 94
  • 187
  • [this](http://stackoverflow.com/questions/3305561/how-to-query-mongodb-with-like) might help you – Yogesh May 24 '15 at 18:48
  • 1
    Don't expect either part of the query to be any fast. `$ne` is slow, and non-rooted regexs are slower. As to the question, .net requires you to explicitly create a `BsonRegularExpression`. – mnemosyn May 24 '15 at 19:01
  • @yogesh - the problem is with the c# driver, what you have offered is not, thanks. – SexyMF May 25 '15 at 03:31
  • @mnemosyn please explain. this is the only way I see to do string,cintains, thanks – SexyMF May 25 '15 at 03:32

0 Answers0