Refactoring MongoDb operators; adding docblock.

- extract() should be avoided if possible. As it makes
  the origin of variables intransparent.

- Reducing line count and amount of temporary variables.

- Fixing coding standard violation.
Fixing expectException usage.