graphql-compose / graphql-compose-mongoose

Mongoose model converter to GraphQL types with resolvers for graphql-compose https://github.com/nodkz/graphql-compose
MIT License
709 stars 94 forks source link

Preserve the array order when using findbyIds #418

Closed susyabashti closed 1 year ago

susyabashti commented 1 year ago

I can't seem to get this to work, i use findbyIds to populate an array of object ids, but it keeps reordering them by the id. someone know what i need to do to fix this?

example:

    63398d312940b0d8da89e1c1
    62e7d0f168db432caf5c8ff7
    62e7d11b68db432caf5c8ff8
    63398d6c2940b0d8da89e1c8

returns :

    62e7d0f168db432caf5c8ff7
    62e7d11b68db432caf5c8ff8
    63398d312940b0d8da89e1c1
    63398d6c2940b0d8da89e1c8

i tried the sort: false, but it didn't help.

susyabashti commented 1 year ago

Note: i just pasted the object ids, but i actually populate them with the data, this doesn't happen when i don't populate them

nodkz commented 1 year ago

It is the internal behavior of MongoDB to return records in its own order.

This lib uses find({_id: { $in: [x, y, z] }}) under the hood here https://github.com/graphql-compose/graphql-compose-mongoose/blob/master/src/resolvers/findByIds.ts#L84