I have a list of street names and I want to select all that start with "Al". In my mysql I would do something like
SELECT * FROM streets WHERE "street_name" LIKE "Al%"
How about mongodb using php?
I have a list of street names and I want to select all that start with "Al". In my mysql I would do something like
SELECT * FROM streets WHERE "street_name" LIKE "Al%"
How about mongodb using php?
here is my working example:
$collection.find({"name": /.*Al.*/})
or, similar,
$collection.find({"name": /Al/})
You're looking for something that contains "Al" somewhere (SQL's '%' operator is equivalent to regexps' '.*'), not something that has "Al" anchored to the beginning of the string.
View for more details
MongoRegex has been deprecated.
Use MongoDB\BSON\Regex
Use a regular expression:
or:
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions
Turning this into PHP:
See: http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart
Also, highly recommend just using the native mongodb connector from PHP instead of a wrapper. It's way faster than any wrapper.
http://php.net/class.mongodb