Mongo Playground

Configuration

[{"_id":332,"vendors":[{"count":6,"products":[{"count":6}]}]},{"_id":464,"vendors":[{"count":10,"products":[{"count":10}]}]},{"_id":538,"vendors":[{"count":9,"products":[{"count":9}]}]},{"_id":437,"vendors":[{"count":13,"products":[{"count":13}]}]},{"_id":352,"vendors":[{"count":8,"products":[{"count":8}]}]},{"_id":498,"vendors":[{"count":9,"products":[{"count":9}]}]},{"_id":329,"vendors":[{"count":8,"products":[{"count":8}]}]},{"_id":467,"vendors":[{"count":9,"products":[{"count":9}]}]},{"_id":430,"vendors":[{"count":13,"products":[{"count":13}]}]},{"_id":291,"vendors":[{"count":5,"products":[{"count":5}]}]},{"_id":192,"vendors":[{"count":2,"products":[{"count":2}]}]},{"_id":441,"vendors":[{"count":13,"products":[{"count":13}]}]},{"_id":466,"vendors":[{"count":10,"products":[{"count":10}]}]},{"_id":445,"vendors":[{"count":13,"products":[{"count":13}]}]},{"_id":465,"vendors":[{"count":9,"products":[{"count":9}]}]}]

Query

db.collection.aggregate([{"$replaceRoot":{"newRoot":{"$arrayToObject":[[{"k":{"$toString":"$_id"},"v":{"count":{"$arrayElemAt":["$vendors.count",0]},"products":{"count":{"$arrayElemAt":["$vendors.count",0]}}}}]]}}}])

Result