Reputation: 30
I'm looking for MySQL's equivalent of
SELECT * FROM table WHERE field1 LIKE '%somestring%' AND field2 LIKE '%anotherstring%'
I did try a couple of things, including
'field1' => '/somestring/i', 'field2' => '/anotherstring/i'
I'm getting no results back, or just data based upon one of the two fields. Is this not possible in MongoDB?
Upvotes: 1
Views: 325
Reputation: 9458
db.collection.find({field1: {$regex: /somestring/i}, field2: {$regex: /anotherstring/i}});
In php
you should do by MongoRegex
.
array(field1 => new MongoRegex("/somestring/i"), field2 => new MongoRegex("/anotherstring/i"))
Upvotes: 2