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?
Use a regular expression:
db.streets.find( { street_name : /^Al/i } );
or:
db.streets.find( { street_name : { $regex : '^Al', $options: 'i' } } );
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions
Turning this into PHP:
$regex = new MongoRegex("/^Al/i");
$collection->find(array('street_name' => $regex));
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
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