, , , , , , , ,

Applicable to Mongo 2.4

MongoDB uses cursors to iterate over resultant documents from a query execution. There are cursor for document records and index records. MongoDB uses Btree to manage document indexes and uses class BtreeCursor to implement cursor management of indexes.

  • Code is under ./src/mongo/db/btreecursor.cpp.
  • class BtreeCursorImpl is implementation of class BtreeCursor
  • Cursor is initialized using BtreeCursorImpl( NamespaceDetails* a , int b, const IndexDetails& c )
  • A Btree bucket has ordered pairs of key=BSON(field) and value=DiskLoc of data record
  • Cursor iterates over each pair of <key, value=””>
  • BtreeCursor requires implementation of the following:
    • locate a key and return its DiskLoc (_locate())
    • Return BSON(key) for a given offset keyofs (keyNode())
    • Move cursor in a backward/forward direction from a given key, offset (_advanceTo())
    • Since cached info about an index could get changed during iteration (checkLocation())