Details
-
Improvement
-
Resolution: Done
-
Blocker - P1
-
None
-
MongoDB V2.6.4 64bits, Windows 7 64bits
*Location*: http://docs.mongodb.org/manual/reference/glossary/#term-natural-order
*User-Agent*: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36
*Referrer*: http://docs.mongodb.org/manual/reference/command/cloneCollectionAsCapped/
*Screen Resolution*: 1920 x 1080
*repo*: docs
*source*: reference/glossary
MongoDB V2.6.4 64bits, Windows 7 64bits *Location*: http://docs.mongodb.org/manual/reference/glossary/#term-natural-order *User-Agent*: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36 *Referrer*: http://docs.mongodb.org/manual/reference/command/cloneCollectionAsCapped/ *Screen Resolution*: 1920 x 1080 *repo*: docs *source*: reference/glossary
Description
There are some explanation and many reference to the concept of natural order (i.e. $natural operator) : the order of documents of collection stored on disk.
(http://docs.mongodb.org/manual/reference/glossary/#term-natural-order)
At first, I believe it. But I start to doubt it after some practical test. I find this natural order is actually an alias of insertion order. Below is my test:
> db.cc.find();
|
> db.cc.insert([{_id:1},{_id:2},{_id:3},{_id:4}]);
|
BulkWriteResult({
|
"writeErrors" : [ ],
|
"writeConcernErrors" : [ ],
|
"nInserted" : 4,
|
"nUpserted" : 0,
|
"nMatched" : 0,
|
"nModified" : 0,
|
"nRemoved" : 0,
|
"upserted" : [ ]
|
})
|
> db.cc.find();
|
{ "_id" : 1 }
|
{ "_id" : 2 }
|
{ "_id" : 3 }
|
{ "_id" : 4 }
|
> db.cc.find().showDiskLoc();
|
{ "_id" : 1, "$diskLoc" : { "file" : 0, "offset" : 401584 } }
|
{ "_id" : 2, "$diskLoc" : { "file" : 0, "offset" : 401648 } }
|
{ "_id" : 3, "$diskLoc" : { "file" : 0, "offset" : 401712 } }
|
{ "_id" : 4, "$diskLoc" : { "file" : 0, "offset" : 401776 } }
|
> db.cc.remove({_id:2});
|
WriteResult({ "nRemoved" : 1 })
|
> db.cc.find();
|
{ "_id" : 1 }
|
{ "_id" : 3 }
|
{ "_id" : 4 }
|
> db.cc.find().showDiskLoc();
|
{ "_id" : 1, "$diskLoc" : { "file" : 0, "offset" : 401584 } }
|
{ "_id" : 3, "$diskLoc" : { "file" : 0, "offset" : 401712 } }
|
{ "_id" : 4, "$diskLoc" : { "file" : 0, "offset" : 401776 } }
|
> db.cc.insert({_id:2});
|
WriteResult({ "nInserted" : 1 })
|
> db.cc.find();
|
{ "_id" : 1 }
|
{ "_id" : 3 }
|
{ "_id" : 4 }
|
{ "_id" : 2 }
|
> db.cc.find().showDiskLoc();
|
{ "_id" : 1, "$diskLoc" : { "file" : 0, "offset" : 401584 } }
|
{ "_id" : 3, "$diskLoc" : { "file" : 0, "offset" : 401712 } }
|
{ "_id" : 4, "$diskLoc" : { "file" : 0, "offset" : 401776 } }
|
{ "_id" : 2, "$diskLoc" : { "file" : 0, "offset" : 401648 } }
|
>
|
-------------------------
The space of {_id:2} has been reused on disk. But the output order changed. Why? I think there is some mechanism to maintain insertion order that assure above output order, which is not told on the manual. Is it right?