Moving data around in an aggregation stage

Hi Edwin,
Continuing to what Peter mentioned, here is a sample query that you can try

db.collection.aggregate([
    {
        $addFields: {
            foos: {
                $arrayToObject: {
                    $map: {
                        input: "$foos",
                        as: "foo",
                        in: {
                            k: "$$foo.code",
                            v: "$$foo.article.$id"
                        }
                    }
                }
            }
        }
    }
]);
1 Like