0

I have the following SQL statement

SELECT Currency, TransTime, AuthTime FROM MONIES WHERE Currency not like 'USD%';

If the SQL statement were simply a "LIKE" query, it would yield the following MongoDB statement

db.MONIES.find({
        "Currency": "USD%"
    }, {
        "Currency": 1,
        "TransTime": 1,
        "AuthTime": 1
});

Is this the proper query for a "NOT LIKE" equivalent? I think this is correct per the documentation for the 'not' operator, but I'd like to double check with Stackoverflow

db.MONIES.find({
        "Currency": { $not: { $like: 'USD%' } }
    }, {
        "Currency": 1,
        "TransTime": 1,
        "AuthTime": 1
});
Kyte
  • 834
  • 2
  • 12
  • 27
  • there is no $like operator, I think you are looking for regular expressions http://docs.mongodb.org/manual/reference/operator/query/regex/ – Asya Kamsky May 16 '14 at 18:59

1 Answers1

2

The page you link actually has an example of what you want to do:

db.inventory.find( { item: { $not: /^p.*/ } } )

There is no $like operator, but MongoDB supports regular expressions.

Asya Kamsky
  • 41,784
  • 5
  • 109
  • 133