這是 MongoDB 中的檔案示例之一。
{
"content" : "I just said that before. I'll never be with you.",
"analysis" : [
{
"sentence" : "I just said that before.",
"sentiment" : "neutral",
"subject" : "I",
"expression" : "say"
},
{
"sentence" : "I'll never be with you.",
"sentiment" : "negative",
"subject" : "I",
"expression" : "be",
"label": "Farewell"
}
]
}
每個分析元素都可以有“標簽”或沒有。
我想過濾此檔案以在分析元素中放置“標簽”。
我需要檔案清單 analysis.label.count < analysis.count
我試過這個查詢
{ $and: [{ "analysis": { $exists: true } }, { "analysis.label": { $exists: false } }] }。
但它回傳的任何分析元素中都沒有標簽。
我需要聚合()嗎?或 find() 與查詢?
uj5u.com熱心網友回復:
它需要$elemMatch運算子匹配$exists陣列中的假條件,
{
analysis: {
$exists: true,
$elemMatch: {
label: {
$exists: false
}
}
}
}
操場
第二種方法檢查null條件,
{
analysis: {
$exists: true
},
"analysis.label": null
}
操場
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/350918.html
標籤:MongoDB
上一篇:如何設定從多個GCP專案到同一個MongoDB集群的網路對等連接
下一篇:更新mongodb中的Key
