Leave a comment

November 5, 2016 by oneOokay

MMAP: collection level

Wired Tiger: (Faster than MMAP)

  • managing its own storage, offers compression – of data/index
  • document level concurrency. No locks
  • No in place update. (Append only update)


mongod --storageEngine wiredTiger
mongod -dbpath WT --storageEngine wiredTiger
//MongoDB can't run wiredTiger engine on the folder that MMAP ran. 
You have to create a new folder and then run it with wiredTiger Engine.


Indexes: A set of ordered things. (BTree in mongo index search)

  • index: (a, b, c) => search okay: a; a,b; a,b,c;  NO: c; c,b;
  • with index: writes slower, reads: faster. index takes time to build/maintain and takes up space.

Creating indexes:

  • db.foo.explain().find(): “winningPlan”; db.foo.explain(true).find(): with more detailed result, can know how many document it scanned.
  • db.students.createIndex({student_id:1}); index on “student_id” decending.
  • db.foo.createIndex({student_id:1, class_id:-1}): create compound index.

Discovering (and deleting) indexes:

  • db.foo.getIndexes();
  • db.foo.dropIndex({student_id:1})

Multikey indexes: create indexes on arrays:

  • can’t create index on two arrays. can create index on one array and one attribute.
  • once you created a compound index which includes one array already, then you will not be able to insert array for the other element in the index, it will be illegal

Dot Notation and Multikey


differences: use explain to explore.

  • db.foo.find({‘$and’:[{‘scores.type’:’exam’}, {‘scores.score’:{‘$gt’:99.8}}]})
  • db.foo.find({‘scores’:{‘$elemMatch:{type:’exam’, score:{‘$gt’:99.8}}}})

Index Creating Option, Unique

  • db.foo.createIndex({thing:1},{unique:true}): create index on an attribute that have unique values.
  • db.foo.remove({thing:’apple’}, {justOne:true})

Index Creation, Sparse: create indexes that some records have index key missing

  • db.foo.createIndex({aaa:1}, {unique:true, sparse: true})
  • sparse index can’t be used for sorting because it will do a full scan.

Index Creation, Background:

  • default is foreground: fast, blocks writers and readers in the same colletion.
  • background: slower, wont block reader and writers.
  • create index on a different server than the server that you db are using.
  • db.foo.createIndex({‘scores.score’:1}, {background: true})
  • creating an index in the background takes longer than creating it in the forground.
  • Although the database server will continue to take requests, a background index creation will still blocks the mongo shell that you are using to create the index.

Use explain:






Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: