简体   繁体   English

$不执行和操作

[英]$not not performing $and operation

I just started exploring mongoDB. 我刚刚开始探索mongoDB。 During that time I managed to create a simple collection with the following data, 在此期间,我设法使用以下数据创建了一个简单的集合,

db.test.insert({name : "joe", age : 20});
db.test.insert({name: "james", age : 25});

Now I have queried it by using, 现在我已经通过使用查询了

db.test.find({name : {$not : {$eq : "joe", $eq: "james"}}})

It yielded me the following result, 它给我带来了以下结果,

{name : "joe", age : 20}

I am confused here, Is it not an and operation like below, 我在这里感到困惑,是不是和下面的操作一样,

SELECT * FROM test where not name = "joe" and not name = "james"

Doubt1: If yes then how the above mentioned mongo query can be interpreted as a normal mysql query? 疑问1:如果是,那么上述mongo查询如何解释为普通的mysql查询? [Note : I am coming from a mysql background.] Please explain. [注意:我来自mysql背景。]请解释。

Doubt2: Also explain about the following mongo query, 疑问2:还要说明有关以下mongo查询的信息,

db.test.find({name : "joe", age : 20});

Is the above query equals to select * from test where name='joe' and age=20 ? 上面的查询是否等于select * from test where name='joe' and age=20 If not then how it would be interpreted as a normal mysql query? 如果没有,那么它将如何解释为普通的mysql查询?

When you are creating an object with {$eq : "joe", $eq: "james"} you are using the same object key twice. 当使用{$eq : "joe", $eq: "james"}创建对象时,您使用相同的对象键两次。 So james will overwrite joe because both use the same object key $eq . james将覆盖joe因为它们都使用相同的对象键$eq

To do your query, you can try something like NOT (name = "joe" OR name = "james") . 要进行查询,您可以尝试使用NOT (name = "joe" OR name = "james") So you add the OR to your mongo query: 因此,您将OR添加到mongo查询中:

db.test.find({name : {$nor: [{$eq: "joe"}, $eq: "james"]}})

Reference 参考

I guess Christoph cleared your doubts. 我猜克里斯多夫(Christoph)消除了您的疑虑。

For SQL to Mongo Query reference visit this link 有关SQL to Mongo Query的参考,请访问链接

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

相关问题 执行模运算的其他方式 - Other ways of performing modulo operation 优雅地在多个选择器上执行相同的操作? - Performing the same operation on multiple selectors, elegantly? 在vue.js中使用Vuex执行CRUD操作时出错 - Error performing a CRUD operation using Vuex in vuejs 查找文本并根据其存在执行操作 - Locating text and performing operation based on its existence 等待2个异步API调用的结果,然后再执行操作 - Waiting for the result of 2 asynchronous API calls before performing an operation 在道具集上的高阶组件内执行逻辑运算 - Performing logical operation inside Higher Order Component on prop set 在不使用返回值的情况下执行映射操作是反模式吗? - Is performing a mapping operation without using returned value an antipattern? 通过对每对值执行一个运算将两个数组合并为一个数组 - Combine two arrays into an array by performing an operation for each pair of values 使用定性的运行时数据实时执行简单的数学运算 - Performing a Simple Math Operation in Real Time with Runtime Data in Qualtrics 预期2-3个参数,但是在执行POST操作时角度为4? - Expected 2-3 arguments but got 4 in angular while performing POST operation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM