1
SELECT 
Member_strMobileNo,
strMembername
FROM tblMembers WITH (NOLOCK)
WHERE CHARINDEX (LOWER(@strMembername), LOWER(strMembername)) > 0
OR CHARINDEX (LOWER(@strMobileNo), LOWER(Member_strMobileNo)) > 0

This is my SQL query I want to fetch data from MongoDB using C# driver .. My Json Structure is :

{
 "memberName" : "seema",
 "Email" : seema@gmail.com
  "Mob"  : 9876543
}

Actually this query is used fro searching details.

In mongo i tried this ,

 var query = Query.Or(Query.In("memberName",  BsonRegularExpression.Create(String.Format("/{0}/i", strMemberName)) ),
                                     new QueryDocument("Mob", BsonRegularExpression.Create(String.Format("/{0}/i", strMobileNo))).

But i guess this query will not be fine since because of resource expensive BsonRegularExpression.Check this this answer in that.

I am using c#, mongoDb, mongodb C# native driver.

How to optimise this.. I am new to mongoDb.. Thanks for all replies..

Community
  • 1
  • 1
Seema
  • 67
  • 1
  • 6

2 Answers2

1

You can do this with an aggregate, project $toLower See: http://docs.mongodb.org/manual/reference/operator/aggregation/toLower/

Something like: db.posts.aggregate([{$project:{date2:"$date",title:{$toLower:"$title"}}}

Alan Spencer
  • 566
  • 3
  • 12
0

There is no easy way to do it efficiently with MongoDB.

I suggest you maintain a lower case version of your fields (eg. normalizedMemberName), have them indexed and use them for your queries.

Reda
  • 2,289
  • 17
  • 19