梦里花落0921
只要你的数据库是3.4.4以上的话直接调用$objectToArray就可以了。#数据:{"_id":2,"item":"ABC2",dimensions:{l:50,w:25,uom:"cm"}}{"_id":3,"item":"XYZ1",dimensions:{l:70,w:75,uom:"cm"}}#查询:db.inventory.aggregate([{$project:{item:1,dimensions:{$objectToArray:"$dimensions"}}}])#结果:{"_id":2,"item":"ABC2","dimensions":[{"k":"l","v":50},{"k":"w","v":25},{"k":"uom","v":"cm"}]}{"_id":3,"item":"XYZ1","dimensions":[{"k":"l","v":70},{"k":"w","v":75},{"k":"uom","v":"cm"}]}