Docker中的MongoDB容器的db.collection顺序是搞乱的,文档总是插在集合的中间

我有一个localhost mongodb收集行为是适当的。 但是,当我试图在docker集装箱内testing这个mongorestored集合时,我遇到了麻烦。

我的所有文件都会插入到collections中。 示例如下:

db.posts.find().pretty() { "_id" : ObjectId("595cc2a803297da443e36a1a"), "name" : "First post", "__v" : 0 } { "_id" : ObjectId("595cc31e03297da443e36a1c"), "name" : "Second post", "__v" : 0 } db.posts.insert({name: "Third post"}) WriteResult({ "nInserted" : 1 }) db.posts.insert({name: "Fourth post}) WriteResult({ "nInserted" : 1 }) db.posts.find().pretty() { "_id" : ObjectId("595cc2a803297da443e36a1a"), "name" : "First post", "__v" : 0 } { "_id" : ObjectId("5964c37ba4e0e8004c4c20d2"), "name" : "Third post", "__v" : 0 } { "_id" : ObjectId("5964c41fd1302fc68fac6ee0"), "name" : "Fourth post", "__v" : 0 } { "_id" : ObjectId("595cc31e03297da443e36a1c"), "name" : "Second post", "__v" : 0 } 

由于felix提到的默认sorting行为并不明显,但是在我将Docker容器主映像从MongoDB 3.0.15更改为3.4之后,问题消失了,最后一个插入的post被按照预期追加到集合上。