Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-4062

Comment on: "manual/reference/glossary.txt" - natural order

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Blocker - P1 Blocker - P1
    • v1.3.12
    • None
    • manual

    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?

      Attachments

        Activity

          People

            andrew.aldridge@mongodb.com Andrew Aldridge
            xgen-internal-docs Docs Collector User (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              9 years, 19 weeks, 2 days ago