[Help] Sorting many documents, by string in the object

{
"GuildId": "435440611760406538",
    "GuildOwner": "246646936713691136",
    "Guild": {
        "Id": 2,
        "Name": "Toxic",
        "Description": "Testing",
        "RoleId": "933600716923207701",
        "RoleColor": "#A600FF",
        "CreatedAt": 1642658156124
    },
    "Members": ["246646936713691136", "926104390752948297"]
}
{
"GuildId": "353906689281490954",
    "GuildOwner": "246646936713691136",
    "Guild": {
        "Id": 1,
        "Name": "Testing",
        "Description": "Testing",
        "RoleId": "933600716923207701",
        "RoleColor": "#A600FF",
        "CreatedAt": 1642658156124
    },
    "Members": ["246646936713691136"],
}

i need to sort string Id(a-b) into object Guild in his document, and return data from smallest to largest

Hi @Anime_Flame ,

I need you to clarify, do you need objects to be sorted by “Guild.id” which is the embedded field or you need to sort the string under GuildId field?

The first one can be done by passing it into a query sort :

.sort({"Guild.id" : 1})

Thanks
Pavel

I need to sort all the documents in the database based on the Id field inside the Guild object from the largest Id to the smallest.

Ok so the solution I gave you should work.