Given a list of entries like the ones below, I want to $unset platformA in a pipeline stage if the _id is in myArray.
const myArray = ['5f22f9ac6ee02a6707cf0586']
db.profiles.findOne({_id: ObjectId("5f22f9ac6ee02a6707cf0586")})
{
"_id" : ObjectId("5f22f9ac6ee02a6707cf0586"),
"platformA" : {
...
},
"platformB": {
...
}
}
So that after the project the result is
{
"_id" : ObjectId("5f22f9ac6ee02a6707cf0586")
"platformB": {
...
}
}
I dont understand how I can access the $_id field and conditionally $project platformA to 0 if it is not in myArray.
{
// only show platformA when not in myArray
$project: {
platformA: 0
}
},