Sha256: 7519f6acdde293bea43a709b4894ec3f219791cb5b3ee1d9a6237e479dc8e960

Contents?: true

Size: 1.22 KB

Versions: 13

Compression:

Stored size: 1.22 KB

Contents

$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
require 'pp'

include XGen::Mongo::Driver

host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT

puts "Connecting to #{host}:#{port}"
db = Mongo.new(host, port).db('ruby-mongo-examples')
coll = db.collection('test')

# Remove all records, if any
coll.clear

# Insert record with all sorts of values
coll.insert('array' => [1, 2, 3],
            'string' => 'hello',
            'hash' => {'a' => 1, 'b' => 2},
            'date' => Time.now, # milliseconds only; microseconds are not stored
            'oid' => ObjectID.new,
            'binary' => Binary.new([1, 2, 3]),
            'int' => 42,
            'float' => 33.33333,
            'regex' => /foobar/i,
            'boolean' => true,
            '$where' => Code.new('this.x == 3'),
            'dbref' => DBRef.new(coll.name, ObjectID.new),

# NOTE: the undefined type is not saved to the database properly. This is a
# Mongo bug. However, the undefined type may go away completely.
#             'undef' => Undefined.new,

            'null' => nil,
            'symbol' => :zildjian)

pp coll.find().next_object

coll.clear

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
animehunter-mongo-0.9 examples/types.rb
mongodb-mongo-0.10.1 examples/types.rb
mongodb-mongo-0.10 examples/types.rb
mongodb-mongo-0.11.1 examples/types.rb
mongodb-mongo-0.11 examples/types.rb
mongodb-mongo-0.12 examples/types.rb
mongodb-mongo-0.6.4 examples/types.rb
mongodb-mongo-0.6.5 examples/types.rb
mongodb-mongo-0.6.6 examples/types.rb
mongodb-mongo-0.6.7 examples/types.rb
mongodb-mongo-0.7 examples/types.rb
mongodb-mongo-0.8 examples/types.rb
mongodb-mongo-0.9 examples/types.rb