require 'mongo' require 'bson_minihash' collection = Mongo::Connection.new('127.0.0.1', 27017).db('test').collection('artists') # Digestion mini_hash = BSONMiniHash.digest("Syd Vicious", :md5) p mini_hash collection.insert(name: "Syd Vicious", hash: mini_hash) doc = collection.find_one(hash: mini_hash) p doc # Packing a hash you already have mini_hash = BSONMiniHash.pack("3eaace90e5526e5acc96f1d6db146b0ed401c2fe", :sha1) collection.insert(name: "Geddy Lee", hash: mini_hash) doc = collection.find_one(hash: mini_hash) p doc # Unpacking a mini hash p BSONMiniHash.unpack(doc['hash'])