mongodb-mongo 0.12 → 0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +12 -12
- data/Rakefile +1 -1
- data/bin/bson_benchmark.rb +1 -1
- data/bin/mongo_console +3 -3
- data/bin/run_test_script +2 -2
- data/bin/standard_benchmark +3 -3
- data/examples/admin.rb +3 -3
- data/examples/benchmarks.rb +2 -2
- data/examples/blog.rb +4 -4
- data/examples/capped.rb +3 -3
- data/examples/cursor.rb +3 -3
- data/examples/gridfs.rb +4 -4
- data/examples/index_test.rb +11 -11
- data/examples/info.rb +3 -3
- data/examples/queries.rb +3 -3
- data/examples/simple.rb +3 -3
- data/examples/strict.rb +3 -3
- data/examples/types.rb +4 -9
- data/lib/mongo.rb +35 -3
- data/lib/mongo/admin.rb +56 -60
- data/lib/mongo/collection.rb +368 -320
- data/lib/mongo/connection.rb +166 -0
- data/lib/mongo/cursor.rb +206 -209
- data/lib/mongo/db.rb +478 -489
- data/lib/mongo/errors.rb +8 -9
- data/lib/mongo/gridfs/chunk.rb +66 -70
- data/lib/mongo/gridfs/grid_store.rb +406 -410
- data/lib/mongo/message/get_more_message.rb +8 -13
- data/lib/mongo/message/insert_message.rb +7 -11
- data/lib/mongo/message/kill_cursors_message.rb +7 -12
- data/lib/mongo/message/message.rb +58 -62
- data/lib/mongo/message/message_header.rb +19 -24
- data/lib/mongo/message/msg_message.rb +5 -9
- data/lib/mongo/message/opcodes.rb +10 -15
- data/lib/mongo/message/query_message.rb +42 -46
- data/lib/mongo/message/remove_message.rb +8 -12
- data/lib/mongo/message/update_message.rb +9 -13
- data/lib/mongo/query.rb +84 -88
- data/lib/mongo/types/binary.rb +13 -17
- data/lib/mongo/types/code.rb +9 -13
- data/lib/mongo/types/dbref.rb +10 -14
- data/lib/mongo/types/objectid.rb +103 -107
- data/lib/mongo/types/regexp_of_holding.rb +18 -22
- data/lib/mongo/types/undefined.rb +7 -10
- data/lib/mongo/util/bson.rb +4 -9
- data/lib/mongo/util/xml_to_ruby.rb +1 -3
- data/mongo-ruby-driver.gemspec +33 -32
- data/{tests → test}/mongo-qa/_common.rb +1 -1
- data/{tests → test}/mongo-qa/admin +1 -1
- data/{tests → test}/mongo-qa/capped +1 -1
- data/{tests → test}/mongo-qa/count1 +4 -4
- data/{tests → test}/mongo-qa/dbs +1 -1
- data/{tests → test}/mongo-qa/find +1 -1
- data/{tests → test}/mongo-qa/find1 +1 -1
- data/{tests → test}/mongo-qa/gridfs_in +2 -2
- data/{tests → test}/mongo-qa/gridfs_out +2 -2
- data/{tests → test}/mongo-qa/indices +2 -2
- data/{tests → test}/mongo-qa/remove +1 -1
- data/{tests → test}/mongo-qa/stress1 +1 -1
- data/{tests → test}/mongo-qa/test1 +1 -1
- data/{tests → test}/mongo-qa/update +1 -1
- data/{tests → test}/test_admin.rb +3 -3
- data/{tests → test}/test_bson.rb +4 -4
- data/{tests → test}/test_byte_buffer.rb +0 -0
- data/{tests → test}/test_chunk.rb +4 -4
- data/{tests → test}/test_collection.rb +42 -4
- data/{tests/test_mongo.rb → test/test_connection.rb} +35 -11
- data/test/test_cursor.rb +223 -0
- data/{tests → test}/test_db.rb +12 -12
- data/{tests → test}/test_db_api.rb +28 -33
- data/{tests → test}/test_db_connection.rb +3 -3
- data/{tests → test}/test_grid_store.rb +4 -4
- data/{tests → test}/test_message.rb +1 -1
- data/{tests → test}/test_objectid.rb +3 -3
- data/{tests → test}/test_ordered_hash.rb +0 -0
- data/{tests → test}/test_round_trip.rb +6 -2
- data/{tests → test}/test_threading.rb +3 -3
- data/test/test_xgen.rb +73 -0
- metadata +33 -32
- data/lib/mongo/mongo.rb +0 -164
- data/tests/test_cursor.rb +0 -121
data/README.rdoc
CHANGED
@@ -7,9 +7,9 @@ many more.
|
|
7
7
|
|
8
8
|
require 'mongo'
|
9
9
|
|
10
|
-
include
|
10
|
+
include Mongo
|
11
11
|
|
12
|
-
db =
|
12
|
+
db = Connection.new('localhost').db('sample-db')
|
13
13
|
coll = db.collection('test')
|
14
14
|
|
15
15
|
coll.clear
|
@@ -70,7 +70,7 @@ Here's how to start mongo and run the "simple.rb" example:
|
|
70
70
|
$ cd path/to/mongo-ruby-driver
|
71
71
|
$ ruby examples/simple.rb
|
72
72
|
|
73
|
-
See also the test code, especially
|
73
|
+
See also the test code, especially test/test_db_api.rb.
|
74
74
|
|
75
75
|
= The Driver
|
76
76
|
|
@@ -79,8 +79,8 @@ Here is some simple example code:
|
|
79
79
|
require 'rubygems' # not required for Ruby 1.9
|
80
80
|
require 'mongo'
|
81
81
|
|
82
|
-
include
|
83
|
-
db =
|
82
|
+
include Mongo
|
83
|
+
db = Connection.new.db('my-db-name')
|
84
84
|
things = db.collection('things')
|
85
85
|
|
86
86
|
things.clear
|
@@ -147,10 +147,10 @@ generate _id values. If you want to control _id values or even their types,
|
|
147
147
|
using a PK factory lets you do so.
|
148
148
|
|
149
149
|
You can tell the Ruby Mongo driver how to create primary keys by passing in
|
150
|
-
the :pk option to the
|
150
|
+
the :pk option to the Connection#db method.
|
151
151
|
|
152
|
-
include
|
153
|
-
db =
|
152
|
+
include Mongo
|
153
|
+
db = Connection.new.db('dbname', :pk => MyPKFactory.new)
|
154
154
|
|
155
155
|
A primary key factory object must respond to :create_pk, which should take a
|
156
156
|
hash and return a hash which merges the original hash with any primary key
|
@@ -164,7 +164,7 @@ Here is a sample primary key factory, taken from the tests:
|
|
164
164
|
|
165
165
|
class TestPKFactory
|
166
166
|
def create_pk(row)
|
167
|
-
row['_id'] ||=
|
167
|
+
row['_id'] ||= Mongo::ObjectID.new
|
168
168
|
row
|
169
169
|
end
|
170
170
|
end
|
@@ -178,7 +178,7 @@ ActiveRecord-like framework for non-Rails apps) and the AR Mongo adapter code
|
|
178
178
|
def create_pk(row)
|
179
179
|
return row if row[:_id]
|
180
180
|
row.delete(:_id) # in case it exists but the value is nil
|
181
|
-
row['_id'] ||=
|
181
|
+
row['_id'] ||= Mongo::ObjectID.new
|
182
182
|
row
|
183
183
|
end
|
184
184
|
end
|
@@ -205,7 +205,7 @@ completely harmless; strict mode is a programmer convenience only.
|
|
205
205
|
To turn on strict mode, either pass in :strict => true when obtaining a DB
|
206
206
|
object or call the :strict= method:
|
207
207
|
|
208
|
-
db =
|
208
|
+
db = Connection.new.db('dbname', :strict => true)
|
209
209
|
# I'm feeling lax
|
210
210
|
db.strict = false
|
211
211
|
# No, I'm not!
|
@@ -233,7 +233,7 @@ If you have the source code, you can run the tests.
|
|
233
233
|
$ rake test
|
234
234
|
|
235
235
|
The tests assume that the Mongo database is running on the default port. You
|
236
|
-
can override the default host (localhost) and port (
|
236
|
+
can override the default host (localhost) and port (Connection::DEFAULT_PORT) by
|
237
237
|
using the environment variables MONGO_RUBY_DRIVER_HOST and
|
238
238
|
MONGO_RUBY_DRIVER_PORT.
|
239
239
|
|
data/Rakefile
CHANGED
@@ -16,7 +16,7 @@ gem_command = "gem1.9" if $0.match(/1\.9$/) # use gem1.9 if we used rake1.9
|
|
16
16
|
|
17
17
|
# NOTE: some of the tests assume Mongo is running
|
18
18
|
Rake::TestTask.new do |t|
|
19
|
-
t.test_files = FileList['
|
19
|
+
t.test_files = FileList['test/test*.rb']
|
20
20
|
end
|
21
21
|
|
22
22
|
desc "Generate documentation"
|
data/bin/bson_benchmark.rb
CHANGED
data/bin/mongo_console
CHANGED
@@ -7,14 +7,14 @@ require 'irb'
|
|
7
7
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
8
8
|
require 'mongo'
|
9
9
|
|
10
|
-
include
|
10
|
+
include Mongo
|
11
11
|
|
12
12
|
host = org_argv[0] || ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
13
|
-
port = org_argv[1] || ENV['MONGO_RUBY_DRIVER_PORT'] ||
|
13
|
+
port = org_argv[1] || ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
14
14
|
dbnm = org_argv[2] || ENV['MONGO_RUBY_DRIVER_DB'] || 'ruby-mongo-console'
|
15
15
|
|
16
16
|
puts "Connecting to #{host}:#{port} (CONN) on with database #{dbnm} (DB)"
|
17
|
-
CONN =
|
17
|
+
CONN = Connection.new(host, port)
|
18
18
|
DB = CONN.db(dbnm)
|
19
19
|
|
20
20
|
puts "Starting IRB session..."
|
data/bin/run_test_script
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
HERE=`dirname $0`
|
7
7
|
|
8
|
-
if [ ! -f $HERE/../
|
8
|
+
if [ ! -f $HERE/../test/mongo-qa/$1 ] ; then
|
9
9
|
exit 0
|
10
10
|
fi
|
11
11
|
|
12
12
|
begintime=`date`
|
13
|
-
ruby $HERE/../
|
13
|
+
ruby $HERE/../test/mongo-qa/$1 $3 $4 >> $2
|
14
14
|
exitval=$?
|
15
15
|
endtime=`date`
|
16
16
|
|
data/bin/standard_benchmark
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
6
6
|
require 'mongo'
|
7
7
|
|
8
|
-
include
|
8
|
+
include Mongo
|
9
9
|
|
10
10
|
TRIALS = 2
|
11
11
|
PER_TRIAL = 5000
|
@@ -50,9 +50,9 @@ def benchmark(str, proc, n, db, coll_name, object, setup=nil)
|
|
50
50
|
end
|
51
51
|
|
52
52
|
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
53
|
-
port = ENV['MONGO_RUBY_DRIVER_PORT'] ||
|
53
|
+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
54
54
|
|
55
|
-
connection =
|
55
|
+
connection = Connection.new(host, port)
|
56
56
|
connection.drop_database("benchmark")
|
57
57
|
db = connection.db('benchmark')
|
58
58
|
|
data/examples/admin.rb
CHANGED
@@ -2,13 +2,13 @@ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
2
2
|
require 'mongo'
|
3
3
|
require 'pp'
|
4
4
|
|
5
|
-
include
|
5
|
+
include Mongo
|
6
6
|
|
7
7
|
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
8
|
-
port = ENV['MONGO_RUBY_DRIVER_PORT'] ||
|
8
|
+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
9
9
|
|
10
10
|
puts "Connecting to #{host}:#{port}"
|
11
|
-
db =
|
11
|
+
db = Connection.new(host, port).db('ruby-mongo-examples')
|
12
12
|
coll = db.create_collection('test')
|
13
13
|
|
14
14
|
# Erase all records from collection, if any
|
data/examples/benchmarks.rb
CHANGED
@@ -4,10 +4,10 @@ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
4
4
|
require 'mongo'
|
5
5
|
|
6
6
|
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
7
|
-
port = ENV['MONGO_RUBY_DRIVER_PORT'] ||
|
7
|
+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Connection::DEFAULT_PORT
|
8
8
|
|
9
9
|
puts "Connecting to #{host}:#{port}"
|
10
|
-
db =
|
10
|
+
db = Mongo::Connection.new(host, port).db('ruby-mongo-examples')
|
11
11
|
coll = db.collection('test')
|
12
12
|
coll.clear
|
13
13
|
|
data/examples/blog.rb
CHANGED
@@ -5,17 +5,17 @@ class Exception
|
|
5
5
|
"%s: %s\n%s" % [self.class, message, (backtrace || []).join("\n") << "\n"]
|
6
6
|
end
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
10
10
|
require 'mongo'
|
11
11
|
|
12
|
-
include
|
12
|
+
include Mongo
|
13
13
|
|
14
14
|
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
15
|
-
port = ENV['MONGO_RUBY_DRIVER_PORT'] ||
|
15
|
+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
16
16
|
|
17
17
|
puts ">> Connecting to #{host}:#{port}"
|
18
|
-
DB =
|
18
|
+
DB = Connection.new(host, port).db('ruby-mongo-blog')
|
19
19
|
|
20
20
|
LINE_SIZE = 120
|
21
21
|
puts "=" * LINE_SIZE
|
data/examples/capped.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
2
2
|
require 'mongo'
|
3
3
|
|
4
|
-
include
|
4
|
+
include Mongo
|
5
5
|
|
6
6
|
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
7
|
-
port = ENV['MONGO_RUBY_DRIVER_PORT'] ||
|
7
|
+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
8
8
|
|
9
9
|
puts "Connecting to #{host}:#{port}"
|
10
|
-
db =
|
10
|
+
db = Connection.new(host, port).db('ruby-mongo-examples')
|
11
11
|
db.drop_collection('test')
|
12
12
|
|
13
13
|
# A capped collection has a max size and optionally a max number of records.
|
data/examples/cursor.rb
CHANGED
@@ -2,13 +2,13 @@ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
2
2
|
require 'mongo'
|
3
3
|
require 'pp'
|
4
4
|
|
5
|
-
include
|
5
|
+
include Mongo
|
6
6
|
|
7
7
|
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
8
|
-
port = ENV['MONGO_RUBY_DRIVER_PORT'] ||
|
8
|
+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
9
9
|
|
10
10
|
puts "Connecting to #{host}:#{port}"
|
11
|
-
db =
|
11
|
+
db = Connection.new(host, port).db('ruby-mongo-examples')
|
12
12
|
coll = db.collection('test')
|
13
13
|
|
14
14
|
# Erase all records from collection, if any
|
data/examples/gridfs.rb
CHANGED
@@ -2,14 +2,14 @@ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
2
2
|
require 'mongo'
|
3
3
|
require 'mongo/gridfs'
|
4
4
|
|
5
|
-
include
|
6
|
-
include
|
5
|
+
include Mongo
|
6
|
+
include GridFS
|
7
7
|
|
8
8
|
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
9
|
-
port = ENV['MONGO_RUBY_DRIVER_PORT'] ||
|
9
|
+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
10
10
|
|
11
11
|
puts "Connecting to #{host}:#{port}"
|
12
|
-
db =
|
12
|
+
db = Connection.new(host, port).db('ruby-mongo-examples')
|
13
13
|
|
14
14
|
def dump(db, fname)
|
15
15
|
GridStore.open(db, fname, 'r') { |f| puts f.read }
|
data/examples/index_test.rb
CHANGED
@@ -3,22 +3,22 @@ class Exception
|
|
3
3
|
"%s: %s\n%s" % [self.class, message, (backtrace || []).join("\n") << "\n"]
|
4
4
|
end
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
8
8
|
require 'mongo'
|
9
9
|
|
10
|
-
include
|
10
|
+
include Mongo
|
11
11
|
|
12
12
|
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
13
|
-
port = ENV['MONGO_RUBY_DRIVER_PORT'] ||
|
13
|
+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
14
14
|
|
15
15
|
puts ">> Connecting to #{host}:#{port}"
|
16
|
-
db =
|
16
|
+
db = Connection.new(host, port).db('ruby-mongo-index_test')
|
17
17
|
|
18
18
|
puts ">> Dropping collection test"
|
19
19
|
begin
|
20
20
|
res = db.drop_collection('test')
|
21
|
-
puts "dropped : #{res.inspect}"
|
21
|
+
puts "dropped : #{res.inspect}"
|
22
22
|
rescue => e
|
23
23
|
puts "Error: #{e.errmsg}"
|
24
24
|
end
|
@@ -26,7 +26,7 @@ end
|
|
26
26
|
puts ">> Creating collection test"
|
27
27
|
begin
|
28
28
|
coll = db.collection('test')
|
29
|
-
puts "created : #{coll.inspect}"
|
29
|
+
puts "created : #{coll.inspect}"
|
30
30
|
rescue => e
|
31
31
|
puts "Error: #{e.errmsg}"
|
32
32
|
end
|
@@ -59,8 +59,8 @@ puts "created index: #{res.inspect}"
|
|
59
59
|
|
60
60
|
puts ">> Gathering index information"
|
61
61
|
begin
|
62
|
-
res = coll.index_information
|
63
|
-
puts "index_information : #{res.inspect}"
|
62
|
+
res = coll.index_information
|
63
|
+
puts "index_information : #{res.inspect}"
|
64
64
|
rescue => e
|
65
65
|
puts "Error: #{e.errmsg}"
|
66
66
|
end
|
@@ -76,7 +76,7 @@ end
|
|
76
76
|
|
77
77
|
puts ">> Dropping index"
|
78
78
|
begin
|
79
|
-
res = coll.drop_index "
|
79
|
+
res = coll.drop_index "all_1"
|
80
80
|
puts "dropped : #{res.inspect}"
|
81
81
|
rescue => e
|
82
82
|
puts "Error: #{e.errmsg}"
|
@@ -105,8 +105,8 @@ end
|
|
105
105
|
|
106
106
|
puts ">> Gathering index information"
|
107
107
|
begin
|
108
|
-
res = coll.index_information
|
109
|
-
puts "index_information : #{res.inspect}"
|
108
|
+
res = coll.index_information
|
109
|
+
puts "index_information : #{res.inspect}"
|
110
110
|
rescue => e
|
111
111
|
puts "Error: #{e.errmsg}"
|
112
112
|
end
|
data/examples/info.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
2
2
|
require 'mongo'
|
3
3
|
|
4
|
-
include
|
4
|
+
include Mongo
|
5
5
|
|
6
6
|
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
7
|
-
port = ENV['MONGO_RUBY_DRIVER_PORT'] ||
|
7
|
+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
8
8
|
|
9
9
|
puts "Connecting to #{host}:#{port}"
|
10
|
-
db =
|
10
|
+
db = Connection.new(host, port).db('ruby-mongo-examples')
|
11
11
|
coll = db.collection('test')
|
12
12
|
|
13
13
|
# Erase all records from collection, if any
|
data/examples/queries.rb
CHANGED
@@ -2,13 +2,13 @@ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
2
2
|
require 'mongo'
|
3
3
|
require 'pp'
|
4
4
|
|
5
|
-
include
|
5
|
+
include Mongo
|
6
6
|
|
7
7
|
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
8
|
-
port = ENV['MONGO_RUBY_DRIVER_PORT'] ||
|
8
|
+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
9
9
|
|
10
10
|
puts "Connecting to #{host}:#{port}"
|
11
|
-
db =
|
11
|
+
db = Connection.new(host, port).db('ruby-mongo-examples')
|
12
12
|
coll = db.collection('test')
|
13
13
|
|
14
14
|
# Remove all records, if any
|
data/examples/simple.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
2
2
|
require 'mongo'
|
3
3
|
|
4
|
-
include
|
4
|
+
include Mongo
|
5
5
|
|
6
6
|
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
7
|
-
port = ENV['MONGO_RUBY_DRIVER_PORT'] ||
|
7
|
+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
8
8
|
|
9
9
|
puts "Connecting to #{host}:#{port}"
|
10
|
-
db =
|
10
|
+
db = Connection.new(host, port).db('ruby-mongo-examples')
|
11
11
|
coll = db.collection('test')
|
12
12
|
|
13
13
|
# Erase all records from collection, if any
|
data/examples/strict.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
2
2
|
require 'mongo'
|
3
3
|
|
4
|
-
include
|
4
|
+
include Mongo
|
5
5
|
|
6
6
|
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
7
|
-
port = ENV['MONGO_RUBY_DRIVER_PORT'] ||
|
7
|
+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
8
8
|
|
9
9
|
puts "Connecting to #{host}:#{port}"
|
10
|
-
db =
|
10
|
+
db = Connection.new(host, port).db('ruby-mongo-examples')
|
11
11
|
|
12
12
|
db.drop_collection('does-not-exist')
|
13
13
|
db.create_collection('test')
|
data/examples/types.rb
CHANGED
@@ -2,13 +2,13 @@ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
2
2
|
require 'mongo'
|
3
3
|
require 'pp'
|
4
4
|
|
5
|
-
include
|
5
|
+
include Mongo
|
6
6
|
|
7
7
|
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
8
|
-
port = ENV['MONGO_RUBY_DRIVER_PORT'] ||
|
8
|
+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
9
9
|
|
10
10
|
puts "Connecting to #{host}:#{port}"
|
11
|
-
db =
|
11
|
+
db = Connection.new(host, port).db('ruby-mongo-examples')
|
12
12
|
coll = db.collection('test')
|
13
13
|
|
14
14
|
# Remove all records, if any
|
@@ -25,13 +25,8 @@ coll.insert('array' => [1, 2, 3],
|
|
25
25
|
'float' => 33.33333,
|
26
26
|
'regex' => /foobar/i,
|
27
27
|
'boolean' => true,
|
28
|
-
'
|
28
|
+
'where' => Code.new('this.x == 3'),
|
29
29
|
'dbref' => DBRef.new(coll.name, ObjectID.new),
|
30
|
-
|
31
|
-
# NOTE: the undefined type is not saved to the database properly. This is a
|
32
|
-
# Mongo bug. However, the undefined type may go away completely.
|
33
|
-
# 'undef' => Undefined.new,
|
34
|
-
|
35
30
|
'null' => nil,
|
36
31
|
'symbol' => :zildjian)
|
37
32
|
|
data/lib/mongo.rb
CHANGED
@@ -5,16 +5,48 @@ require 'mongo/types/regexp_of_holding'
|
|
5
5
|
require 'mongo/types/undefined'
|
6
6
|
|
7
7
|
require 'mongo/errors'
|
8
|
-
require 'mongo/
|
8
|
+
require 'mongo/connection'
|
9
9
|
require 'mongo/message'
|
10
10
|
require 'mongo/db'
|
11
11
|
require 'mongo/cursor'
|
12
12
|
require 'mongo/collection'
|
13
13
|
require 'mongo/admin'
|
14
14
|
|
15
|
+
module Mongo
|
16
|
+
ASCENDING = 1
|
17
|
+
DESCENDING = -1
|
18
|
+
end
|
19
|
+
|
20
|
+
# DEPRECATED - the XGen namespace is deprecated and will be removed - use Mongo or GridFS instead
|
21
|
+
MongoCopy = Mongo
|
15
22
|
module XGen
|
23
|
+
require 'mongo/gridfs'
|
24
|
+
GridFSCopy = GridFS
|
25
|
+
|
26
|
+
def self.included(other_module)
|
27
|
+
warn "the XGen module is deprecated and will be removed - use Mongo or GridFS instead (included from: #{other_module})"
|
28
|
+
end
|
29
|
+
|
16
30
|
module Mongo
|
17
|
-
|
18
|
-
|
31
|
+
include MongoCopy
|
32
|
+
|
33
|
+
def self.included(other_module)
|
34
|
+
warn "the XGen::Mongo module is deprecated and will be removed - use Mongo instead (included from: #{other_module})"
|
35
|
+
end
|
36
|
+
|
37
|
+
module Driver
|
38
|
+
include MongoCopy
|
39
|
+
|
40
|
+
def self.included(other_module)
|
41
|
+
warn "the XGen::Mongo::Driver module is deprecated and will be removed - use Mongo instead (included from: #{other_module})"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
module GridFS
|
45
|
+
include GridFSCopy
|
46
|
+
|
47
|
+
def self.included(other_module)
|
48
|
+
warn "the XGen::Mongo::GridFS module is deprecated and will be removed - use GridFS instead (included from: #{other_module})"
|
49
|
+
end
|
50
|
+
end
|
19
51
|
end
|
20
52
|
end
|