Mongo on Speed


Add to your Gemfile and bundle; otherwise,

gem install faststep


Connect to mongo:

>> conn = # defaults to

Or connect to a custom host and port:

>> conn ="", 12345)

Pick a database:

>> db = conn.db("awesome_development")

Have some fun!

>> db["users"].count
=> 0
>> db["users"].insert( {|i| { :name => "Person #{i}" } }
=> true
>> db["users"].count
=> 10000
>> db["users"].count(:name => /0$/)
=> 1000
>> db["users"].find(:name => /0$/).to_a
=> [{"_id"=>BSON::ObjectId('4d83c53555ca381d572c1cf7'), "name"=>"Person 0"}, {"_id"=>BSON::ObjectId('4d83c53555ca381d572c1d01'), "name"=>"Person 10"}, ...]
>> db["users"].remove(:name => /0$/)
=> true
>> db["users"].count(:name => /0$/)
=> 0
>> db["users"].count
=> 9000
>> db["users"].drop
=> true
>> db.drop
=> true


This is under heavy development (what gem isn't?) but there's a lot of stuff to be implemented still. It's not nearly as smart as the mongo Ruby driver and it doesn't handle errors that well.


  • Connection pooling
  • Safe mode (per database or connection)
  • Master/slave
  • Replica sets

Basically, most of


This is a C extension that uses the Mongo C driver. As of right now, I haven't modified any of the code provided in that driver in here. That code's Apache license still applies, and since it's not a derivative work (I haven't changed any of the source), I'm using an MIT license for Faststep.

I've basically copied the benchmark from the Mongo Ruby driver to test Faststep's speed, and all operations are anywhere between 10% (finding ranges on large docs) and 120% faster (inserting small/medium indexed documents and inserting small/medium documents in batches). See for benchmarks.

I started writing this driver for a project I'm working on called Crowdtap, which uses Mongo as its primary data store. I'd dabbled in C extensions before and figured I could leverage this knowledge to speed up certain operations we were doing. If it wasn't for them and their belief that I could get something usable in a short time, this project probably wouldn't exist; thanks guys!


The Mongo C driver code has retained its Apache license; I've released faststep under an MIT license (see LICENSE for details).


Written 2011 by Josh Clayton.