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
@@ -14,31 +14,27 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
# ++
|
16
16
|
|
17
|
-
module
|
18
|
-
module Mongo
|
19
|
-
module Driver
|
17
|
+
module Mongo
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
19
|
+
# A Regexp that can hold on to extra options and ignore them. Mongo
|
20
|
+
# regexes may contain option characters beyond 'i', 'm', and 'x'. (Note
|
21
|
+
# that Mongo only uses those three, but that regexes coming from other
|
22
|
+
# languages may store different option characters.)
|
23
|
+
#
|
24
|
+
# Note that you do not have to use this class at all if you wish to
|
25
|
+
# store regular expressions in Mongo. The Mongo and Ruby regex option
|
26
|
+
# flags are the same. Storing regexes is discouraged, in any case.
|
27
|
+
class RegexpOfHolding < Regexp
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
# +str+ and +options+ are the same as Regexp. +extra_options_str+
|
34
|
-
# contains all the other flags that were in Mongo but we do not use or
|
35
|
-
# understand.
|
36
|
-
def initialize(str, options, extra_options_str)
|
37
|
-
super(str, options)
|
38
|
-
@extra_options_str = extra_options_str
|
39
|
-
end
|
40
|
-
end
|
29
|
+
attr_accessor :extra_options_str
|
41
30
|
|
31
|
+
# +str+ and +options+ are the same as Regexp. +extra_options_str+
|
32
|
+
# contains all the other flags that were in Mongo but we do not use or
|
33
|
+
# understand.
|
34
|
+
def initialize(str, options, extra_options_str)
|
35
|
+
super(str, options)
|
36
|
+
@extra_options_str = extra_options_str
|
42
37
|
end
|
43
38
|
end
|
39
|
+
|
44
40
|
end
|
@@ -14,18 +14,15 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
# ++
|
16
16
|
|
17
|
-
module
|
18
|
-
module Mongo
|
19
|
-
module Driver
|
17
|
+
module Mongo
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
# NOTE: this class does not attempt to provide ANY of the semantics an
|
25
|
-
# "unknown" object might need. It isn't nil, it isn't special in any
|
26
|
-
# way, and there isn't any singleton value.
|
27
|
-
class Undefined < Object; end
|
19
|
+
# DEPRECATED - the ruby driver converts the BSON undefined type to nil,
|
20
|
+
# and saves this type as nil
|
21
|
+
class Undefined < Object
|
28
22
|
|
23
|
+
def initialize
|
24
|
+
super
|
25
|
+
warn "the Undefined type is deprecated and will be removed - BSON undefineds get implicitly converted to nil now"
|
29
26
|
end
|
30
27
|
end
|
31
28
|
end
|
data/lib/mongo/util/bson.rb
CHANGED
@@ -26,7 +26,7 @@ require 'mongo/types/undefined'
|
|
26
26
|
# A BSON seralizer/deserializer.
|
27
27
|
class BSON
|
28
28
|
|
29
|
-
include
|
29
|
+
include Mongo
|
30
30
|
|
31
31
|
MINKEY = -1
|
32
32
|
EOO = 0
|
@@ -135,7 +135,7 @@ class BSON
|
|
135
135
|
when BINARY
|
136
136
|
serialize_binary_element(@buf, k, v)
|
137
137
|
when UNDEFINED
|
138
|
-
|
138
|
+
serialize_null_element(@buf, k)
|
139
139
|
when CODE_W_SCOPE
|
140
140
|
serialize_code_w_scope(@buf, k, v)
|
141
141
|
else
|
@@ -207,7 +207,7 @@ class BSON
|
|
207
207
|
doc[key] = nil
|
208
208
|
when UNDEFINED
|
209
209
|
key = deserialize_cstr(@buf)
|
210
|
-
doc[key] =
|
210
|
+
doc[key] = nil
|
211
211
|
when REF
|
212
212
|
key = deserialize_cstr(@buf)
|
213
213
|
doc[key] = deserialize_dbref_data(@buf)
|
@@ -385,11 +385,6 @@ class BSON
|
|
385
385
|
end
|
386
386
|
end
|
387
387
|
|
388
|
-
def serialize_undefined_element(buf, key)
|
389
|
-
buf.put(UNDEFINED)
|
390
|
-
self.class.serialize_cstr(buf, key)
|
391
|
-
end
|
392
|
-
|
393
388
|
def serialize_boolean_element(buf, key, val)
|
394
389
|
buf.put(BOOLEAN)
|
395
390
|
self.class.serialize_cstr(buf, key)
|
@@ -543,7 +538,7 @@ class BSON
|
|
543
538
|
when Symbol
|
544
539
|
SYMBOL
|
545
540
|
when Undefined
|
546
|
-
|
541
|
+
NULL
|
547
542
|
else
|
548
543
|
raise "Unknown type of object: #{o.class.name}"
|
549
544
|
end
|
@@ -21,7 +21,7 @@ require 'mongo'
|
|
21
21
|
# an OrderedHash.
|
22
22
|
class XMLToRuby
|
23
23
|
|
24
|
-
include
|
24
|
+
include Mongo
|
25
25
|
|
26
26
|
def xml_to_ruby(io)
|
27
27
|
doc = REXML::Document.new(io)
|
@@ -63,8 +63,6 @@ class XMLToRuby
|
|
63
63
|
regex_to_ruby(e.elements)
|
64
64
|
when 'null'
|
65
65
|
nil
|
66
|
-
when 'undefined'
|
67
|
-
Undefined.new
|
68
66
|
when 'doc'
|
69
67
|
doc_to_ruby(e)
|
70
68
|
else
|
data/mongo-ruby-driver.gemspec
CHANGED
@@ -19,6 +19,7 @@ PACKAGE_FILES = ['README.rdoc', 'Rakefile', 'mongo-ruby-driver.gemspec',
|
|
19
19
|
'examples/types.rb',
|
20
20
|
'lib/mongo/admin.rb',
|
21
21
|
'lib/mongo/collection.rb',
|
22
|
+
'lib/mongo/connection.rb',
|
22
23
|
'lib/mongo/cursor.rb',
|
23
24
|
'lib/mongo/db.rb',
|
24
25
|
'lib/mongo/gridfs/chunk.rb',
|
@@ -36,7 +37,6 @@ PACKAGE_FILES = ['README.rdoc', 'Rakefile', 'mongo-ruby-driver.gemspec',
|
|
36
37
|
'lib/mongo/message/remove_message.rb',
|
37
38
|
'lib/mongo/message/update_message.rb',
|
38
39
|
'lib/mongo/message.rb',
|
39
|
-
'lib/mongo/mongo.rb',
|
40
40
|
'lib/mongo/query.rb',
|
41
41
|
'lib/mongo/types/binary.rb',
|
42
42
|
'lib/mongo/types/code.rb',
|
@@ -49,40 +49,41 @@ PACKAGE_FILES = ['README.rdoc', 'Rakefile', 'mongo-ruby-driver.gemspec',
|
|
49
49
|
'lib/mongo/util/ordered_hash.rb',
|
50
50
|
'lib/mongo/util/xml_to_ruby.rb',
|
51
51
|
'lib/mongo.rb']
|
52
|
-
TEST_FILES = ['
|
53
|
-
'
|
54
|
-
'
|
55
|
-
'
|
56
|
-
'
|
57
|
-
'
|
58
|
-
'
|
59
|
-
'
|
60
|
-
'
|
61
|
-
'
|
62
|
-
'
|
63
|
-
'
|
64
|
-
'
|
65
|
-
'
|
66
|
-
'
|
67
|
-
'
|
68
|
-
'
|
69
|
-
'
|
70
|
-
'
|
71
|
-
'
|
72
|
-
'
|
73
|
-
'
|
74
|
-
'
|
75
|
-
'
|
76
|
-
'
|
77
|
-
'
|
78
|
-
'
|
79
|
-
'
|
80
|
-
'
|
81
|
-
'
|
52
|
+
TEST_FILES = ['test/mongo-qa/_common.rb',
|
53
|
+
'test/mongo-qa/admin',
|
54
|
+
'test/mongo-qa/capped',
|
55
|
+
'test/mongo-qa/count1',
|
56
|
+
'test/mongo-qa/dbs',
|
57
|
+
'test/mongo-qa/find',
|
58
|
+
'test/mongo-qa/find1',
|
59
|
+
'test/mongo-qa/gridfs_in',
|
60
|
+
'test/mongo-qa/gridfs_out',
|
61
|
+
'test/mongo-qa/indices',
|
62
|
+
'test/mongo-qa/remove',
|
63
|
+
'test/mongo-qa/stress1',
|
64
|
+
'test/mongo-qa/test1',
|
65
|
+
'test/mongo-qa/update',
|
66
|
+
'test/test_admin.rb',
|
67
|
+
'test/test_bson.rb',
|
68
|
+
'test/test_byte_buffer.rb',
|
69
|
+
'test/test_chunk.rb',
|
70
|
+
'test/test_collection.rb',
|
71
|
+
'test/test_connection.rb',
|
72
|
+
'test/test_cursor.rb',
|
73
|
+
'test/test_db.rb',
|
74
|
+
'test/test_db_api.rb',
|
75
|
+
'test/test_db_connection.rb',
|
76
|
+
'test/test_grid_store.rb',
|
77
|
+
'test/test_message.rb',
|
78
|
+
'test/test_objectid.rb',
|
79
|
+
'test/test_ordered_hash.rb',
|
80
|
+
'test/test_threading.rb',
|
81
|
+
'test/test_round_trip.rb',
|
82
|
+
'test/test_xgen.rb']
|
82
83
|
|
83
84
|
Gem::Specification.new do |s|
|
84
85
|
s.name = 'mongo'
|
85
|
-
s.version = '0.
|
86
|
+
s.version = '0.13'
|
86
87
|
s.platform = Gem::Platform::RUBY
|
87
88
|
s.summary = 'Ruby driver for the 10gen Mongo DB'
|
88
89
|
s.description = 'A Ruby driver for the 10gen Mongo DB. For more information about Mongo, see http://www.mongodb.org.'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require File.join(File.dirname(__FILE__), '_common.rb')
|
4
|
-
db =
|
4
|
+
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
5
5
|
|
6
6
|
db.collection('test').insert({'test' => 1})
|
7
7
|
admin = db.admin
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require File.join(File.dirname(__FILE__), '_common.rb')
|
4
|
-
db =
|
4
|
+
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
5
5
|
|
6
6
|
if $DEBUG
|
7
7
|
3.times { |i| db.drop_collection("test#{i+1}") }
|
@@ -13,6 +13,6 @@ end
|
|
13
13
|
|
14
14
|
puts db.collection('test1').count
|
15
15
|
puts db.collection('test2').count
|
16
|
-
puts db.collection('test3').
|
17
|
-
puts db.collection('test3').
|
18
|
-
puts db.collection('test3').
|
16
|
+
puts db.collection('test3').find('i' => 'a').count
|
17
|
+
puts db.collection('test3').find('i' => 3).count
|
18
|
+
puts db.collection('test3').find({'i' => {'$gte' => 67}}).count
|
data/{tests → test}/mongo-qa/dbs
RENAMED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require File.join(File.dirname(__FILE__), '_common.rb')
|
4
|
-
db =
|
4
|
+
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
5
5
|
|
6
6
|
if $DEBUG
|
7
7
|
3.times { |i| db.drop_collection("dbs_#{i+1}") }
|
@@ -3,9 +3,9 @@
|
|
3
3
|
require File.join(File.dirname(__FILE__), '_common.rb')
|
4
4
|
|
5
5
|
require 'mongo/gridfs'
|
6
|
-
include
|
6
|
+
include GridFS
|
7
7
|
|
8
|
-
db =
|
8
|
+
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
9
9
|
|
10
10
|
input_file = ARGV[0]
|
11
11
|
|
@@ -3,9 +3,9 @@
|
|
3
3
|
require File.join(File.dirname(__FILE__), '_common.rb')
|
4
4
|
|
5
5
|
require 'mongo/gridfs'
|
6
|
-
include
|
6
|
+
include GridFS
|
7
7
|
|
8
|
-
db =
|
8
|
+
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
9
9
|
|
10
10
|
input_file = ARGV[0]
|
11
11
|
output_file = ARGV[1]
|
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
require File.join(File.dirname(__FILE__), '_common.rb')
|
4
4
|
|
5
|
-
include
|
5
|
+
include Mongo
|
6
6
|
|
7
|
-
db =
|
7
|
+
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
8
8
|
x = db.collection('x')
|
9
9
|
y = db.collection('y')
|
10
10
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
LONG_STRING = "lksjhasoh1298alshasoidiohaskjasiouashoasasiugoas" * 6
|
4
4
|
|
5
5
|
require File.join(File.dirname(__FILE__), '_common.rb')
|
6
|
-
db =
|
6
|
+
db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
|
7
7
|
c = db.collection('stress1')
|
8
8
|
|
9
9
|
n1 = 50_000
|
@@ -5,10 +5,10 @@ require 'test/unit'
|
|
5
5
|
# NOTE: assumes Mongo is running
|
6
6
|
class AdminTest < Test::Unit::TestCase
|
7
7
|
|
8
|
-
include
|
8
|
+
include Mongo
|
9
9
|
|
10
|
-
@@db =
|
11
|
-
|
10
|
+
@@db = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
11
|
+
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test')
|
12
12
|
@@coll = @@db.collection('test')
|
13
13
|
|
14
14
|
def setup
|
data/{tests → test}/test_bson.rb
RENAMED
@@ -5,7 +5,7 @@ require 'test/unit'
|
|
5
5
|
|
6
6
|
class BSONTest < Test::Unit::TestCase
|
7
7
|
|
8
|
-
include
|
8
|
+
include Mongo
|
9
9
|
|
10
10
|
def setup
|
11
11
|
# We don't pass a DB to the constructor, even though we are about to test
|
@@ -85,7 +85,7 @@ class BSONTest < Test::Unit::TestCase
|
|
85
85
|
assert_equal doc, doc2
|
86
86
|
|
87
87
|
r = doc2['doc']
|
88
|
-
assert_kind_of
|
88
|
+
assert_kind_of RegexpOfHolding, r
|
89
89
|
assert_equal '', r.extra_options_str
|
90
90
|
|
91
91
|
r.extra_options_str << 'zywcab'
|
@@ -99,7 +99,7 @@ class BSONTest < Test::Unit::TestCase
|
|
99
99
|
assert_equal doc, doc2
|
100
100
|
|
101
101
|
r = doc2['doc']
|
102
|
-
assert_kind_of
|
102
|
+
assert_kind_of RegexpOfHolding, r
|
103
103
|
assert_equal 'abcwyz', r.extra_options_str # must be sorted
|
104
104
|
end
|
105
105
|
|
@@ -183,7 +183,7 @@ class BSONTest < Test::Unit::TestCase
|
|
183
183
|
doc = {'undef' => Undefined.new}
|
184
184
|
@b.serialize(doc)
|
185
185
|
doc2 = @b.deserialize
|
186
|
-
|
186
|
+
assert_equal nil, doc2['undef']
|
187
187
|
end
|
188
188
|
|
189
189
|
def test_put_id_first
|
File without changes
|
@@ -5,11 +5,11 @@ require 'mongo/gridfs'
|
|
5
5
|
|
6
6
|
class ChunkTest < Test::Unit::TestCase
|
7
7
|
|
8
|
-
include
|
9
|
-
include
|
8
|
+
include Mongo
|
9
|
+
include GridFS
|
10
10
|
|
11
|
-
@@db =
|
12
|
-
|
11
|
+
@@db = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
12
|
+
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-utils-test')
|
13
13
|
@@files = @@db.collection('gridfs.files')
|
14
14
|
@@chunks = @@db.collection('gridfs.chunks')
|
15
15
|
|