2014-05-16 91 views
0

我有以下SQL語句MongoDB的equivelant到SQL 「NOT LIKE」 查詢

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

如果SQL語句是一個簡單的 「喜歡」 查詢時,它會產生以下的MongoDB聲明

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

這是否適用於「不相似」等效的查詢?我想這是每the documentation for the 'not' operator正確的,但我想用加倍#1

db.MONIES.find({ 
     "Currency": { $not: { $like: 'USD%' } } 
    }, { 
     "Currency": 1, 
     "TransTime": 1, 
     "AuthTime": 1 
}); 
+0

沒有$ like操作符,我想你正在尋找正則表達式http://docs.mongodb.org/manual/reference/operator/query/regex/ –

回答

2

The page you link檢查其實有你想要做什麼的例子:

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

沒有$like運營商,但MongoDB支持regular expressions

+0

當然你需要用'貨幣'並用'美元'替換'p' –