node.js - Insert docs in sorted order on mongodb -
In Mangode, I want to enter data in sorted order based on some fields. The way I am doing, compare the data with the data before the insertion, which is in the collection and then insert it on that particular situation. Is possible to combine in a special place using Js?
You can not insert a doctor in a special place in the collection. Even if you can, it will not make any difference because you can not trust the natural order of MongoDB documents because they can run continuously from time to time because the docs are updated in the collection.
Instead, an index on the field (s) requires you to sort your documents, and then in order to efficiently retrieve the docs in your order, include a type of clause in your questions.
The shell in the example:
Comments
Post a Comment