3.6 Aggiornamento:
Usa $match con $expr . $expr consente l'uso di espressioni di aggregazione all'interno di $match fase.
db.collection.aggregate([
{"$match":{
"$expr":{
"$eq":[
{"$size":{"$setIntersection":["$FirstArray.Name","$SecondArray.Name"]}},
0
]
}
}},
{"$project":{"_id":1}}
])
Vecchia versione:
Puoi provare $redact con $setIntersection per la tua domanda.
$setIntersection per confrontare il FirstArray s Name s con SecondArray s Name se restituisce un array di documenti con nomi comuni seguito da $size e $redact e confronta il risultato con 0 per conservare e altrimenti rimuovere il documento.
db.collection.aggregate(
[{
$redact: {
$cond: {
if: {
$eq: [{
$size: {
$setIntersection: ["$FirstArray.Name", "$SecondArray.Name"]
}
}, 0]
},
then: "$$KEEP",
else: "$$PRUNE"
}
}
}, {
$project: {
_id: 1
}
}]
)