-
Notifications
You must be signed in to change notification settings - Fork 532
/
types.rb
36 lines (28 loc) · 1.02 KB
/
types.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'mongo'
require 'pp'
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
db = Connection.new(host, port).db('ruby-mongo-examples')
coll = db.collection('test')
# Remove all records, if any
coll.remove
# 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),
'null' => nil,
'symbol' => :zildjian)
pp coll.find().next_document
coll.remove