Romitou/MongoSK

Sort Collection Expression/Effect

ReportCardsMC opened this issue · 4 comments

An expression in which you can sort a collection and get the result, this would be very useful for getting top players depending on a certain index and value.

Example Syntax: [mongo] sort collection %collection% by %string% from (highest to lowest|lowest to highest)
Example Usage:

set {_sort::*} to sort collection {_collection} by "balance" from highest to lowest
loop 3 times:
    send "%loop-value%. %{_sort::%loop-value%}%" to {_player}

Sure! I'll look as soon as I can free up some time.

This enhancement has been added in the 053607e commit.

Example:

# Inline query:
set {_documents::*} to all descending sorted mongo documents in {collection} by fields "coins" and "joinedTimestamp"

# More unpacked query:
set {_query} to mongo documents in {collection}
set {_sortedQuery} to descending sorted {_query} by fields "number"
set {_documents::*} to all documents of {_sortedQuery}

This commit brings major changes to the code and especially to the way the addon handles queries.
In my opinion, I think that the syntaxes are starting to become difficult to read, so I prefer to warn that the syntaxes added by this commit are very likely to be modified in the future. Please do not hesitate to let me know if there are any problems!

With this, is it possible to sort all documents where a filter is in place as well?

Of course! Unfortunately it seems to me that this new version has some problems. I recommend you to wait for the arrival of the major version 2.0 of MongoSK which will be built more solidly and bring more functionalities, being currently greatly limited by the support of backward compatibility.