mongodbmongomapper

Searching for fields that don't match a regex in MongoMapper


In MongoMapper I can use the following query to search for items based on regex match:

Foo.where(:name => /Foo.*/)

How can I search for items that their name field do not match /Foo.*/?


Solution

  • You can use $not

    db.customers.find( { name : { $not : /acme.*corp/i } } );