我有类似的问题
{
"title": "sjncx",
"desciption": "cknxk jckd",
"price": "29.99",
"stock": "3",
...
}
如果标题 is not empty
.(标题存在且不为空),我需要过滤数据。还有 is empty
喜欢 ~ title: ""
~ (所以标题存在但为空)
我尝试了 is not empty
:
{'title': {'$ne': 'null'}}
我尝试了 is empty
:
{'title': {'$type': 10}}
那行不通。是什么原因?
答案 0 :(得分:1)
答案 1 :(得分:1)
使用 $and 很有表现力
db.collection.find({
"$and": [
{
"title": {
"$ne": null
}
},
{
"title": {
"$ne": ""
}
}
]
})
您只需在那里设置您的条件即可。 doc