0

I'm trying to figure out how to translate a MongoDB aggregate query to Postgres. My schema has an array of strings called array_one, a date field updated, and a cluster field that identifies which documents are clustered together (i.e. share a cluster ID).

What I need to do is find the most popular cluster values of documents that pass a filter (array_one containing a value, updated between a time, etc).

This is my MongoDB aggregate pipeline:

var query = [
      { $match: { array_one: 'INCLUDE_VAL', updated: { $gt: new Date(Date.now() - (1000 * 60 * 60 * trendingDurationHours)), $lt: new Date() } } },
      { $group: {_id: '$cluster', count: { $sum: 1 } } },
      { $sort: { count: -1 } },
      { $limit: 10 }
];

Any idea how to do this in Postgres?

K. Barresi
  • 1,275
  • 1
  • 21
  • 46

0 Answers0