[英]MongoDB, find items matching the term “a” & $nin
我正在嘗試弄清楚如何使此查詢在mongodb中工作。
這是我要執行的查詢(“翻譯為” mysql)
SELECT title FROM artists WHERE name LIKE "%a%" AND id NOT IN(1, 2)
在mongoDB中嘗試
$term = new MongoRegex('/^a/i')l;
$not = array('$nin' => array('_id' => array('1', '2')));
$artists->find(array('name' => $term), $not);
$artists->find(array('name' => $term, $not))
; 我如何使這項工作按預期進行,現在它返回null
這是mongodb的解決方案
db.artists.find({
"name" : /a/,
"id" : {
"$nin" : [1,2]
}
})
只需將每個{}編寫為數組,就可以得到php的答案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.