java - MongoDB Atlas 中的数值搜索如何工作?
问题描述
我是 MongoDB Atlas 的新手。我想执行如下查询,
样本文件:
{
message: "Hello",
role: "student",
status: 1
}
询问
search
WHERE
'Hello' in field 'message'
NOT [1 OR 2] in field 'status'
我尝试了compound
和search
如下,但无法得到我想要的。
compound:{
must:[{
text: {
query: 'Hello',
path: 'message'
}
}],
mustNot:[
{
text: {
query: 1,
path: 'status'
}
},
{
text: {
query: 2,
path: 'status'
}
}
]
}
这会返回一个错误说,
"Query" must be a string (from "compund.mustNot[2].text").
当我将它们设为 String 时,它不会返回任何值。我知道我在这里使用文本搜索,但我找不到任何其他选择。不能在 MongoDB Atlas 中搜索 int 值吗?
解决方案
db.getCollection("yourCollection").find({"message":"Hello","status":{$nin:[1,2]}});
如果你想使用$in
,你可以在下面使用它...使用'$in'
db.getCollection("yourCollection").find({"message":"Hello","status":{$in:[1,2]}});
推荐阅读
- sql - 错误 1055:对不同列和另一列的总和进行分组 - SQL
- git - Pip 在 Gitlab-CI 上使用个人访问令牌安装来自 Gitlab 的私人仓库
- amazon-web-services - AWS Sync S3 与 EC2 澄清问题
- latex - 将图像放在 R-markdown 中以投影仪为中心的顶部
- python - matplotlib imshow(aspect='auto') 产生高度不均匀的行
- c++ - 在工厂类中存储和传递参数包
- gnuplot - 如何在gnuplot中调用字符串中的整数
- python - Python 函数利用传递给它的变量以及未传递给它的变量。有什么区别?
- matlab - Matlab - 如何使用 imfill 填充图像的一部分?
- python-3.x - 使用关键字 Pandas Dataframe Python 进行过滤