mongoose sort by a function
I kind of find a temporary solution. It works but isn't really what I was looking for... the code is really messy and apparently you cannot take arbitrary fn
for sorting..
for example, say fn = (a+3) * (b+5)
Media.aggregate().project({ "type": 1, "status": 1, "newField1": { "$add": [ "$type", 3 ] }, "newField2": { "$add": [ 5, "$status" ] },}).project({ "newField3": { "$multiply": [ "$newField1", "$newField2" ] },}).sort("newField3").exec()