'MongoDB: Get keys and values as separate arrays with new keys

I have the following MongoDB collection.

{
    "timestamp": "10:05:12",
    "value": 100
},
{
    "timestamp": "15:07:01",
    "value": 120
}, ... 

Note: Here "..." implies more data with the same structure.

Expected Result

{
    "timestamps" : ["10:05:12", "15:07:01", ...],
    "values": [100, 120, ...]
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source