Mark Gill
Mark Gill

Reputation: 3781

mongodb regular expressions matching

i am having these kind of strings

"abc?ref1=app";

"abc?ref1=app&xxxxxxxxxxxxxxxxxxxxxxxxxxx"

where xxxxxxxxxxxxxxx is some string...

i want to write regular expression which should only match "abc?ref1=app" types of strings and should not match any other string like "abc?ref1=app&xxxxxxxxxxxxxxxxxxxxxxxxxxx" ..i mean it should only and only match "abc?ref1=app" type of strings...

i have written some thing like this /abc\?ref1=app/ ..but this will also match "abc?ref1=app&xxxxxxxxxxxxxxxxxxxxxxxxxxx"

please tell me how to write regular expression which will only match "abc\?ref1=app"

Upvotes: 1

Views: 688

Answers (2)

DhruvPathak
DhruvPathak

Reputation: 43275

You do not even need regex here, since mongoDB uses lexographical comparison a simple

{ "myStr" : { $lte : "abc?ref1=app" }

where myStr is your db key will work a string like abc?ref1=app&xyz would be counted as greater than your query.

Upvotes: 1

Marcel Jackwerth
Marcel Jackwerth

Reputation: 54802

Add an end-of-line ($) token

abc\?ref1=app$

Upvotes: 0

Related Questions