Sort by frequency of a value in a specific field

There is an internal tool at work that does not allow aggregations.
My challenge is to essentially use
collection.find( {field} ).sort(???)
to order the documents in a way that will improve the productivity of the team.

e.g.
What I want to do is sort the result of a query by the frequency of values of a field.
I’ve fiddled around with a few things and nothing has done what I want.
e.g.
collecton.find( {field} ).sort(???)
key: a
key: a
key: b
key: c
key: b
key: b
key: c
key: x

should be returned in the order
key: b
key: b
key: b
key: a
key: a
key: c (dont care about the order of the values if their frequencies are the same, frequency of a == frequency of c)
key: c
key: x

any ideas?
Is this even possible?

I am not sure I understand correctly the following.

A tool you developed internally or a 3rd party tool that you use internally. If it really does not allow aggregations while you are using MongoDB, it is like driving a Porsche and only allowed to use the first speed.

The best way to

is to modify your internally developed tool to use aggregation or stop using a 3rd party tool that does not allow aggregation.

The problem is that you want to sort on frequencies of values. You either have to store the frequencies in all documents, which is a nightmare to maintain, or compute it on the fly. The only way I see to compute it on the fly without aggregation is to download all the data, compute the frequencies in what ever language your internal non-aggregation friendly tool permits, and then sort using the frequencies you just computed.

$OR simply bypass the tool and use mongosh to run a trivial aggregation that looks like:

group = { "$group" : {
  "_id" : "$key" ,
  "documents" : { "$push" : $$ROOT } ,
  "frequency" : { "$sum" : 1 }
} }
sort = { "$sort" : {
  "frequency" : -1
} }
unwind = { "$unwind" : "documents" }
pipeline = [ group , sort , unwind ]

You might want to do a $replaceRoot after unwind to have the exact result.