简体   繁体   English

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

[英]MongoDB, find items matching the term “a” & $nin

i'm trying, to figure out how can i make this query work in mongodb. 我正在尝试弄清楚如何使此查询在mongodb中工作。

This is the query i'm trying to do ( "translated" to mysql ) 这是我要执行的查询(“翻译为” mysql)

SELECT title FROM artists WHERE name LIKE "%a%" AND id NOT IN(1, 2)

The try in mongoDB 在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)) ; $artists->find(array('name' => $term, $not)) ;

how can i make this work as expected, right now it returns null 我如何使这项工作按预期进行,现在它返回null

Here is a solution for mongodb 这是mongodb的解决方案

db.artists.find({
   "name" : /a/,
   "id" : {
        "$nin" : [1,2]
   }
})

just by writing each {} as an array, you will get the answer for php 只需将每个{}编写为数组,就可以得到php的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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