mongodb-查询“不是null null'不起作用
我正在使用MongoDB表工作,并且在某些字段中获得与NULL不同的值的文档遇到问题。 我假设我正在使用$ ne
错误,但是,给定此文档:
{
"createdAt" : "2022-04-07T13:18:18Z",
"expired" : false,
"responses": [
{
"id": "header",
"options": [
{
"id": "1",
"text": ""
}
],
"textForSearch": null
},
{
"id": "content",
"options": [
{
"id": "content test 01",
"text": "content test 01"
},
{
"id": "content test 02",
"text": "content test 02"
}
],
"title": "test title",
"questionType": "selection",
"textForSearch": null
},
{
"id": "footer",
"options": [
{
"id": "negative",
"text": "Negative"
},
{
"id": "positive",
"text": "Positive"
}
],
"title": "test title",
"questionType": "selection",
"textForSearch": null
},
{
"id": "test_id",
"options": null,
"title": "",
"questionType": "text",
"textForSearch": "comentario de test"
}
]
}
以下查询:
db.getCollection('table').find({"responses.textForSearch": {$ne: null} })
结果:
从1ms中获取0记录。
我想念什么?
I'm working with a MongoDB table and I have problems getting the documents with values different from null in some fields.
I assume that I'm using the $ne
operator wrong, but, given this document:
{
"createdAt" : "2022-04-07T13:18:18Z",
"expired" : false,
"responses": [
{
"id": "header",
"options": [
{
"id": "1",
"text": ""
}
],
"textForSearch": null
},
{
"id": "content",
"options": [
{
"id": "content test 01",
"text": "content test 01"
},
{
"id": "content test 02",
"text": "content test 02"
}
],
"title": "test title",
"questionType": "selection",
"textForSearch": null
},
{
"id": "footer",
"options": [
{
"id": "negative",
"text": "Negative"
},
{
"id": "positive",
"text": "Positive"
}
],
"title": "test title",
"questionType": "selection",
"textForSearch": null
},
{
"id": "test_id",
"options": null,
"title": "",
"questionType": "text",
"textForSearch": "comentario de test"
}
]
}
The following query:
db.getCollection('table').find({"responses.textForSearch": {$ne: null} })
result in:
Fetched 0 record(s) in 1ms.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
$elemMatch
运算符。您可以参考单一查询条件 查看使用
dot notation
和$elemMatch
与$not
或$ne< 一起使用时产生不同结果的示例/代码>运营商。
示例 Mongo Playground
Use
$elemMatch
operator.You may refer to Single Query Condition to see the sample that using
dot notation
and$elemMatch
produce the different results when using with$not
or$ne
operators.Sample Mongo Playground