How do i search and query based on time?

Hello @Bradley_Benjamin, welcome to the MongoDB Community forum!

This can be used for your first query - get all the trading pairs with the price at the latest date.

db.collection.aggregate([
  { 
    $sort: { trading_pair: 1, time_stamp: -1 } 
  },
  { 
    $group: { 
        _id:  "$trading_pair",
        latest_date: { $first: "$time_stamp" },
        recent_price:  { $first: "$price" }
    }
  }
])
1 Like