javascript - Mongodb documents are not arranged in proper order -


when manually insert 5 rows mongodb database can see id field in increasing order when insert 6th row has greater id no comes first when query collection. how insert in increasing order of id field? please help

what happens mongodb generates _id field you. can read more here: create auto-incrementing sequence field

and more objectid.

but constraint on _id is unique, roll out own sequential implementation, not recommended.

generally in mongodb, not use auto-increment pattern _id field, or field, because not scale databases large numbers of documents. typically default value objectid more ideal _id.

if you're sure being 1 inserting values database, timestamp objectid view sort of increment-feeling.

however if want retrieve values in inserted order suggest @ibininja suggests.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -