mongodb - MongoDB $gt/$lt 运算符,数据类型为数组,键值对为字符串。如何比较数组中字符串类型的负值?
问题描述
我正在尝试在 MongoDB Compass 和 Robo 3T 上执行查询,以获取大于/小于用户指定数字的值。在我的数据库中,值的存储方式如下:
"Attributes":
[{
"Key": "Score",
"Value": "-25"
},
{
"Key": "Country",
"Value": "India"
}]
我尝试了以下查询,但没有得到结果。不考虑负号进行比较。
用户指定号码:-27
机器人 3T:
1. db.getCollection('Resource').find({ Attributes: { $elemMatch: { Key:"Score" ,Value: { "$gt" : "-27" }} } })
2. db.getCollection('Resource').find({ Attributes: { $elemMatch: { Key:"Score" ,Value: { "$gt" : -27 }} } })
MongoDB指南针:
{ "Attributes": { $elemMatch: { Key: { $eq: "Score" } ,Value: { $gt:"-27"} } } }
我在这里缺少什么?
解决方案
推荐阅读
- javascript - 反应表单提交问题
- javascript - div改变位置时是否可以创建“幻灯片”过渡?(弹性盒,js)
- javascript - 使用 javascript 为 pdfmake 动态生成行
- arduino - Arduino超声波传感器检测到障碍物后停止转动伺服电机
- python - Python - 列表理解问题:我需要嵌套列表理解吗?
- typescript - 使用 K extends keyof T 时 T[K] 的缩小类型
- python - 我对我在 codeforces 上解决的一个编程问题感到困惑,我认为问题本身是错误的
- python - AttributeError: 'NoneType' 对象没有属性 'get_text' 美丽的汤/request 并且没有输出
- sql - sql server 中的动态更新查询。我需要在变量中传递值,但是当我执行 cammand 时这给了我错误
- sql - 如何选择 group by 未使用的列?