Mongo Hacker

MongoDB Shell Enhancements for Hackers

Vote on HN

by TylerBrock


It's easy, just clone the repo and run make.

$ git clone
$ cd mongo-hacker
$ make


Colorized Shell

API Extensions

Filter for filtering a collection of documents
db.collection.filter() -- accepts less parameters than find, simply matches
One for finding a single document
db.collection.filter({ ... }).one() # equivalent to db.collection.findOne({ ... })
Select for projection
db.collection.filter({ ... }).select({ name: 1 })  # only returns the name and _id fields
Update, Replace, Upsert and Remove can be called on a DBQuery Object
db.collection.filter({ ... }).update({ ... })           # multi update
db.collection.filter({ ... }).replace({ ... })          # single replacement
db.collection.filter({ ... }).upsert({ ... })            # single upsert
db.collection.filter({ ... }).remove()                   # multi remove
Sort, limit, and skip through multi updates and removes
db.collection.filter({ ... }).limit(7).update({ ... })
db.collection.filter({ ... }).sort({ ... }).skip(1).limit(3).update({ ... })
db.collection.filter({ ... }).limit(3).remove()

Aggregation Framework Helpers

Group and Count
gcount(group_field, filter)
Group and Sum
gsum(group_field, sum_field, filter)
Group and Sum
gavg(group_field, avg_field, filter)

Sensible Defaults

Index Paranoia

Print index usage information on every query (default false)

Colorize and Highlight Query Time

Highlights slow running queries

Authors and Contributors

Originally created and conceived of by Tyler Brock (@TylerBrock) and Mike O'Brien (@mpobrien) who work as Software Engineers at 10gen (@10gen) in New York City. Despite being a young project, there have already been many other contributors as we encourage pull requests and criticism. Thank you to everyone who has used or contributed to Mongo Hacker.

Support or Contact

This software comes with no guarantee or warranty and is not endorsed by 10gen in any way.