繁体   English   中英

MongoDB,找到与术语“ a”和$ nin相匹配的项目

[英]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')));

  1. $artists->find(array('name' => $term), $not);
  2. $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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM