For example I have a collection of these object Ids in the array below.........
let ids = [
new ObjectId("628109759af30dbc4a27e130"),
new ObjectId("6280f8edde998a4bebb58923"),
new ObjectId("6280f8f3de998a4bebb5892d"),
new ObjectId("6280f8f0de998a4bebb58928"),
]
when I pass them to this function below....
let results = Model.find({ _id: { $in: ids } }).exec()
I expect the results to be .......
let results = [
{new ObjectId("628109759af30dbc4a27e130"), name:'model1'} ,
{new ObjectId("6280f8edde998a4bebb58923"), name:'model2'},
{new ObjectId("6280f8f3de998a4bebb5892d"), name:'model3'},
{new ObjectId("6280f8f0de998a4bebb58928"), name:'model4'},
]
however , I end up with the results being ......
let results = [
{new ObjectId("6280f8edde998a4bebb58923"), name:'model2'},
{new ObjectId("628109759af30dbc4a27e130"), name:'model1'},
{new ObjectId("6280f8f0de998a4bebb58928"), name:'model4'},
{new ObjectId("6280f8f3de998a4bebb5892d"), name:'model3'},
]
The results are not in the same order as the ids in the original ids array I am passing to it.
Does anyone have an idea on how to get them in the correct order?