Проблема в условии вашего запроса - { "$eq": {"$pull_request": null}}
. Это должно быть одно из следующих значений:
db.test.aggregate( [
{
$addFields: {
hasPullRequest: {
$cond: [
{ $eq: [ "$pull_request", { diff_url: null, patch_url: null, html_url: null } ] },
false,
true
]
}
}
}
] ).pretty()
db.test.aggregate( [
{
$addFields: {
hasPullRequest: {
$cond: [
{ $and: [
{ $eq: [ "$pull_request.diff_url", null ] },
{ $eq: [ "$pull_request.patch_url", null ] },
{ $eq: [ "$pull_request.html_url", null ] }
] },
false,
true
]
}
}
}
] ).pretty()
[EDIT ADD]
db.test.aggregate( [
{
$facet: {
pull_req_no: [
{ $match: { pull_request: { $exists: false } } },
{ $addFields: { hasPullRequest: false } }
],
pull_req_yes: [
{ $match: { pull_request: { $exists: true } } },
{ $addFields: {
hasPullRequest: {
$cond: [
{ $and: [
{ $eq: [ "$pull_request.diff_url", null ] },
{ $eq: [ "$pull_request.patch_url", null ] },
{ $eq: [ "$pull_request.html_url", null ] }
] },
false,
true
]
}
} }
]
}
},
{
$project: { result: { $concatArrays: [ "$pull_req_no", "$pull_req_yes" ] } }
},
{
$unwind: "$result"
},
{
$replaceRoot: { newRoot: "$result" }
}
] ).pretty()