Brug denne:
db.collection.aggregate([
{ $set: { data: { $objectToArray: "$levelNames" } } },
{
$set: {
currentLevelId: {
$arrayElemAt: ["$data.v", { $indexOfArray: ["$data.k", "$levelName"] }]
}
}
},
{ $unset: "data" }
])