$exists aggregateではサポートされていません MongoDBのクエリ 。したがって、aggregate $existsの代わりにクエリ $ifNullを使用できます 。
構文:
{ $ifNull: [ <expression>, <replacement-expression-if-null> ] }
更新:
bを取得するには trueとしての値 またはfalse このクエリを試すことができます
db.test.aggregate([
{
$project: {
b: {
$cond: [
{$ifNull: ['$b', false]}, // if
true, // then
false // else
]
}
}
}
])
説明:
b = $cond: [ 'if condition satisfied', 'then true', 'else false' ];
ここで、condition = {$ifNull: ['$b', false]} ここで$b 存在しない場合、condition = false それ以外の場合、condition = true 。
したがって、condition = trueの場合 次に、次に結果を返します つまり、b = true
if condition = false 次に、その他の結果を返します b = falseを意味します