[DOCS-4062] Comment on: "manual/reference/glossary.txt" - natural order Created: 18/Sep/14  Updated: 08/Dec/16  Resolved: 02/Oct/14

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: None
Fix Version/s: v1.3.12

Type: Improvement Priority: Blocker - P1
Reporter: Docs Collector User (Inactive) Assignee: Andrew Aldridge
Resolution: Done Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

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


Participants:
Days since reply: 9 years, 19 weeks, 2 days ago

 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?



 Comments   
Comment by Githook User [ 06/Oct/14 ]

Author:

{u'username': u'i80and', u'name': u'Andrew Aldridge', u'email': u'i80and@foxquill.com'}

Message: DOCS-4062: Natural order clarification

Signed-off-by: kay <kay.kim@10gen.com>

Conflicts:
source/reference/method/cursor.sort.txt
source/reference/operator/meta/natural.txt
Branch: v2.4
https://github.com/mongodb/docs/commit/e2ae94fc141e94f7b3fc52a3fb3543be58dc14ae

Comment by Githook User [ 06/Oct/14 ]

Author:

{u'username': u'i80and', u'name': u'Andrew Aldridge', u'email': u'i80and@foxquill.com'}

Message: DOCS-4062: Natural order clarification

Signed-off-by: kay <kay.kim@10gen.com>
Branch: master
https://github.com/mongodb/docs/commit/924fc87a9b34c67cc933fb9ca461a9f7647b9700

Generated at Thu Feb 08 07:47:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.