Understanding MongoDB: BtreeCursor

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())

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s