Order of documents returned by $in: [val1, val2, ..., valn]

I have a query that passes an array of ids in a specific order.

    find({
      id: { $in: [5, 3, 4, 1, 2] },
    })

This query returns an array of documents with corresponding ids, but the documents are sorted in the ascending order.

[ {id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}]

Instead I want the returned array to have documents in the same order in which the query specifies the ids. That is

[{id: 5}, {id: 3}, {id: 4}, {id: 1}, {id: 2}]

Is there a way to prevent mongodb from sorting the result?

find({
      id: { $in: [5, 3, 4, 1, 2] },
    }).sort({_id:1})

@David_Tayar - Your solution would sort the array in the ascending order by _id. What I am looking for is not a sorted array of documents, but an array of documents that follow the same order as specified in the $in field.

mongoose - Does MongoDB's $in clause guarantee order - Stack Overflow you might interested in .it was useful for me