In mongo, I'm trying to query for users with an id that ends in a certain number. This number is a parameter that I pass in.
So if I had 4 users [3544,42345,66452,7348], how could i query and just get user 7348 if i was just interested in users whose id ends in 8.
I've looked through here, but can't find exactly what would work for this:
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions
UPDATE: doing this is PHP, and the expected values are int's, not strings. My where clause looks like this: $where = array('uid'=>'/8$/');
If you want to find a user whose id end in the digit 8 you would just have to do this:
db.users.find( { id : /[8]$/ } );
$ matches to the end of the line. just like ^ matches the beginning of the line. refer to this for further details
For finding last digit of int type data fields you would have to use the $mod operator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With