I want a new field in a resultset to be a projection. In which the value is the logical AND of two other fields.
foo and bar are Boolean fields on the collection. I want the new projection fooAndBar to be the result of the logical AND of said fields.
$project : {
'fooAndBar': {
{ $and: { [ {'$foo': 1 }, {'$bar' : 1} ] } }
}
}
I cannot get this to work. I've tried using $cond too. Is this possible, thanks!
Do this, it'll work
{
"$project": {
"fooBar": {
$and: [
"$foo",
"$bar"
]
}
}
}