Problem: I am trying to fetch data from the MongoDB
database as per the defined in an Array of ObjectId's. While fetching the data I have noticed that the data isn't ordered as per the defined ObjectId in the Array field.
module_id: [
ObjectId('60f65202cfq57631f324061b'),
ObjectId('60f66df8cfx57631f324061e'),
ObjectId('60f66bedcfv57631f324061d'),
ObjectId('610262e58eu2031d264e934b'),
ObjectId('611a143bf66m223dd5338641'),
ObjectId('6119efdf4770b836e1ceaf24')
]
Desired Output: I wanted the fetched result should be as per the array ids and I am passing the same order that is defined above but getting some random order result. Don't want to be by default sort.
To fetch the result using .find({ _id: { $in: module_id }}).toArray(function (err, result) {console.log(result)})
Does anybody have any idea where I am doing wrong?