Different collection find() iteration order between client stub and server

Hi,

We have some methods where we pass an array of doc _ids as parameter. We use optimistic UI, so the methods are executed on both the client stub and server.

When a collection.find({ _id: { $in: doc_ids } } ) is executed inside the method, it turns out that the order in which the documents are iterated on the client (minimongo) can be different from the server.

This is a problem in cases where we insert new documents during each iteration, resulting in different doc id’s for the same documents between client stub and server.

Is this normal behavior, or a bug?

The way we solve it now is to add { sort: { _id: 1 } } to these queries, but we just wonder if this behavior is to be expected?

Order is not guaranteed even if you were only on the server or only on the client. Every query may return a different order regardless where the query is called from.

Thanks for your response!

So this is definitely something to realize when using the $in operator with optimistic UI.