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" : [email protected]
  "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..

3
  • Don't use regexes, simply normalize the string to a consistent casing in the same way you're doing it in SQL. Commented Nov 12, 2013 at 11:09
  • 1
    This seems like a better question for codereview.stackexchange.com Commented Nov 12, 2013 at 11:10
  • mnemosyn, sorry I did not Get this Commented Nov 12, 2013 at 11:53

2 Answers 2

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"}}}

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.