need get all key from object in mongodb
$objectToArray
convertspec
object to array in key-value format$unwind
deconstructspec
array$group
by null and construct the unique array ofspec
object's key using$addToSet
db.collection.aggregate([ { $project: { spec: { $objectToArray: "$spec" } } }, { $unwind: "$spec" }, { $group: { _id: null, spec: { $addToSet: "$spec.k" } } }])