There is a listarraylist < long > al = newarraylist < long > (); The ID of the data obtained from the outside is stored in it and sorted (randomly extracted IDs are put into the LIST in sequence), and then these IDs are passed through in Obj. Put (“_ ID”, New Basic DBObject (“$ In”, List)) in mongoDB; In query, the obtained results are not in the same order as the ID in the LIST. After searching, some articles said that mongodb will sort according to $natural if no sorting is specified, but I tested it and it is not the case.
The question now is how can mongodb get the results in the order of list?
This is a very good question. In fact, the articles you checked did not say anything wrong, did not specify the order, and were arranged according to the natural order. It’s just that the natural order is based on
_idThe natural order to row. Yours
listJust a query condition is equivalent to
x > max AND x < minThe specified query range has nothing to do with sorting. No matter what database system you specify, it will be in this one.
listAfter finding the data within the scope, sort it by its own sorting method.
My suggestion is that you still use this method to get the value, and after getting it out, you loop through the java program and then run out of the sorted array.