MongoDB – Get rank of the document based on frequency
[ {_id: 1, query: 'A', createdAt: 1660610671 }, {_id: 2, query: 'A', createdAt: 1660610672 }, {_id: 3, query: 'A', createdAt: 1660610673 }, {_id: 4, query: 'A', createdAt: 1660610674 }, {_id: 5, query: 'B', createdAt: 1660610675 }, {_id: 6, query: 'C',…