node.js - mongoose conditional query returns unexpected doc
问题描述
Records in User Collection:
[
{
"__v": 0,
"_id": "617849bc35a25323c48cdd58",
"email": "mockEmail",
"updatedAt": "2021-10-26T18:32:28.241Z"
},
{
"__v": 0,
"_id": "617849bc35a25323c48cdd5b",
"email": "mockEmail2",
"updatedAt": "2021-10-26T18:32:28.297Z"
}
]
Code been executed:
await User.find({email:"mockEmail",tag:"mockTag"}).exec();
Result:
The first doc is returned
Expected behavior:
No document should be returned since both documents have no tag
.
I tried to:
Run this script on mongoplayground and got the expected result(no document found)
Use $and operator even though I think this is default behavior by mongoose
await User.find({$and:[{email:"mockEmail"},{tag:"mockTag"}]}).exec();
still returned the first doc.
Package Version:
mongoose: 6.0.6
@types/node: 16.9.1
解决方案
推荐阅读
- javascript - 通过 Ajax PHP 和 JavaScript 在表中插入模态数据
- ruby - 比较日期在不同年份不起作用但在同一年份工作正常
- android - 程序类型已经存在:com.google.android.gms.internal.measurement.zzdz
- javascript - JavaScript / Angular将数组中对象的一个属性复制到另一个对象数组?
- jupyter-notebook - 如何使用 jupyter 的 timeit 获取正确的全局变量?
- eclipse - 无法使用 Tomcat 8.5、Java 8 和 Eclipse Photon 4.8.0 为 JSP 编译类
- r - R lavaan 中的高阶相互作用
- .net - Is this controller untestable?
- c++ - 错误:'operator<<' 不匹配(操作数类型是 'std::ostream {aka std::basic_ostream
}' 和 '无效') - javascript - 通过其键数组解构对象