1

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?

Iano
  • 30
  • 4

1 Answers1

2
 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"))
Sushant Gupta
  • 8,980
  • 5
  • 43
  • 48