mongo 0.19.1 → 0.19.2
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 +14 -14
- data/Rakefile +5 -0
- data/bin/gr.rb +14 -0
- data/lib/bson.rb +46 -0
- data/lib/bson/bson_c.rb +20 -0
- data/lib/bson/bson_ruby.rb +601 -0
- data/lib/bson/byte_buffer.rb +224 -0
- data/lib/bson/exceptions.rb +39 -0
- data/lib/bson/ordered_hash.rb +140 -0
- data/lib/bson/types/binary.rb +54 -0
- data/lib/bson/types/code.rb +36 -0
- data/lib/bson/types/dbref.rb +40 -0
- data/lib/bson/types/min_max_keys.rb +58 -0
- data/lib/bson/types/objectid.rb +180 -0
- data/lib/bson/types/regexp_of_holding.rb +45 -0
- data/lib/mongo.rb +4 -2
- data/lib/mongo/collection.rb +61 -20
- data/lib/mongo/connection.rb +18 -4
- data/lib/mongo/cursor.rb +13 -12
- data/lib/mongo/db.rb +11 -29
- data/lib/mongo/gridfs/grid.rb +1 -1
- data/lib/mongo/gridfs/grid_io.rb +4 -0
- data/lib/mongo/util/core_ext.rb +37 -0
- data/lib/mongo/util/support.rb +40 -7
- data/test/auxillary/1.4_features.rb +166 -0
- data/test/collection_test.rb +30 -1
- data/test/connection_test.rb +18 -1
- data/test/cursor_test.rb +14 -0
- data/test/db_api_test.rb +4 -10
- data/test/grid_test.rb +13 -0
- data/test/unit/collection_test.rb +14 -4
- metadata +27 -5
data/test/collection_test.rb
CHANGED
@@ -492,7 +492,36 @@ class TestCollection < Test::Unit::TestCase
|
|
492
492
|
|
493
493
|
context "Creating indexes " do
|
494
494
|
setup do
|
495
|
+
@@db.drop_collection('geo')
|
496
|
+
@@db.drop_collection('test-collection')
|
495
497
|
@collection = @@db.collection('test-collection')
|
498
|
+
@geo = @@db.collection('geo')
|
499
|
+
end
|
500
|
+
|
501
|
+
should "create a geospatial index" do
|
502
|
+
@geo.save({'loc' => [-100, 100]})
|
503
|
+
@geo.create_index([['loc', Mongo::GEO2D]])
|
504
|
+
assert @geo.index_information['loc_2d']
|
505
|
+
end
|
506
|
+
|
507
|
+
should "create a unique index" do
|
508
|
+
@collection.create_index([['a', Mongo::ASCENDING]], true)
|
509
|
+
assert @collection.index_information['a_1']['unique'] == true
|
510
|
+
end
|
511
|
+
|
512
|
+
should "create an index in the background" do
|
513
|
+
if @@version > '1.3.1'
|
514
|
+
@collection.create_index([['b', Mongo::ASCENDING]], :background => true)
|
515
|
+
assert @collection.index_information['b_1']['background'] == true
|
516
|
+
else
|
517
|
+
assert true
|
518
|
+
end
|
519
|
+
end
|
520
|
+
|
521
|
+
should "require an array of arrays" do
|
522
|
+
assert_raise MongoArgumentError do
|
523
|
+
@collection.create_index(['c', Mongo::ASCENDING])
|
524
|
+
end
|
496
525
|
end
|
497
526
|
|
498
527
|
should "generate indexes in the proper order" do
|
@@ -508,7 +537,7 @@ class TestCollection < Test::Unit::TestCase
|
|
508
537
|
end
|
509
538
|
|
510
539
|
should "return properly ordered index information" do
|
511
|
-
|
540
|
+
assert @collection.index_information['b_1_a_1']
|
512
541
|
end
|
513
542
|
end
|
514
543
|
end
|
data/test/connection_test.rb
CHANGED
@@ -58,6 +58,23 @@ class TestConnection < Test::Unit::TestCase
|
|
58
58
|
old_object = @mongo.db('old').collection('copy-test').find.next_document
|
59
59
|
new_object = @mongo.db('new').collection('copy-test').find.next_document
|
60
60
|
assert_equal old_object, new_object
|
61
|
+
@mongo.drop_database('old')
|
62
|
+
@mongo.drop_database('new')
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_copy_database_with_auth
|
66
|
+
@mongo.db('old').collection('copy-test').insert('a' => 1)
|
67
|
+
@mongo.db('old').add_user('bob', 'secret')
|
68
|
+
|
69
|
+
assert_raise Mongo::OperationFailure do
|
70
|
+
@mongo.copy_database('old', 'new', 'localhost', 'bob', 'badpassword')
|
71
|
+
end
|
72
|
+
|
73
|
+
result = @mongo.copy_database('old', 'new', 'localhost', 'bob', 'secret')
|
74
|
+
assert result['ok'].to_i == 1
|
75
|
+
|
76
|
+
@mongo.drop_database('old')
|
77
|
+
@mongo.drop_database('new')
|
61
78
|
end
|
62
79
|
|
63
80
|
def test_database_names
|
@@ -76,7 +93,7 @@ class TestConnection < Test::Unit::TestCase
|
|
76
93
|
logger = Logger.new(output)
|
77
94
|
logger.level = Logger::DEBUG
|
78
95
|
db = Connection.new(@host, @port, :logger => logger).db('ruby-mongo-test')
|
79
|
-
assert output.string.include?("admin
|
96
|
+
assert output.string.include?("admin['$cmd'].find")
|
80
97
|
end
|
81
98
|
|
82
99
|
def test_connection_logger
|
data/test/cursor_test.rb
CHANGED
@@ -376,4 +376,18 @@ class CursorTest < Test::Unit::TestCase
|
|
376
376
|
assert_equal(1, @@coll.find({}, :fields => ["a"]).count())
|
377
377
|
end
|
378
378
|
end
|
379
|
+
|
380
|
+
def test_has_next
|
381
|
+
@@coll.remove
|
382
|
+
200.times do |n|
|
383
|
+
@@coll.save("x" => n)
|
384
|
+
end
|
385
|
+
|
386
|
+
cursor = @@coll.find
|
387
|
+
while cursor.has_next?
|
388
|
+
assert cursor.next_document
|
389
|
+
end
|
390
|
+
|
391
|
+
assert_equal false, cursor.has_next?
|
392
|
+
end
|
379
393
|
end
|
data/test/db_api_test.rb
CHANGED
@@ -133,12 +133,6 @@ class DBAPITest < Test::Unit::TestCase
|
|
133
133
|
assert_equal 2, docs.size
|
134
134
|
assert docs.detect { |row| row['a'] == 1 }
|
135
135
|
assert docs.detect { |row| row['a'] == 2 }
|
136
|
-
|
137
|
-
# Find by advanced query (regexp)
|
138
|
-
docs = @@coll.find('a' => /[1|2]/).to_a
|
139
|
-
assert_equal 2, docs.size
|
140
|
-
assert docs.detect { |row| row['a'] == 1 }
|
141
|
-
assert docs.detect { |row| row['a'] == 2 }
|
142
136
|
end
|
143
137
|
|
144
138
|
def test_find_sorting
|
@@ -287,7 +281,7 @@ class DBAPITest < Test::Unit::TestCase
|
|
287
281
|
assert_equal 2, info.length
|
288
282
|
|
289
283
|
assert info.has_key?(name)
|
290
|
-
assert_equal info[name],
|
284
|
+
assert_equal info[name]["key"], {"a" => 1}
|
291
285
|
ensure
|
292
286
|
@@db.drop_index(@@coll.name, name)
|
293
287
|
end
|
@@ -302,7 +296,7 @@ class DBAPITest < Test::Unit::TestCase
|
|
302
296
|
assert_equal 2, info.length
|
303
297
|
|
304
298
|
assert info.has_key?(name)
|
305
|
-
assert_equal info[name],
|
299
|
+
assert_equal info[name]['key'], {"a" => 1}
|
306
300
|
ensure
|
307
301
|
@@db.drop_index(@@coll.name, name)
|
308
302
|
end
|
@@ -314,7 +308,7 @@ class DBAPITest < Test::Unit::TestCase
|
|
314
308
|
|
315
309
|
assert_equal name, 'a_-1_b_1_c_-1'
|
316
310
|
assert info.has_key?(name)
|
317
|
-
assert_equal [['
|
311
|
+
assert_equal info[name]['key'], {"a" => -1, "b" => 1, "c" => -1}
|
318
312
|
ensure
|
319
313
|
@@db.drop_index(@@coll.name, name)
|
320
314
|
end
|
@@ -326,7 +320,7 @@ class DBAPITest < Test::Unit::TestCase
|
|
326
320
|
|
327
321
|
assert_equal name, 'a_-1_b_1_c_-1'
|
328
322
|
assert info.has_key?(name)
|
329
|
-
assert_equal [['
|
323
|
+
assert_equal info[name]['key'], {"a" => -1, "b" => 1, "c" => -1}
|
330
324
|
ensure
|
331
325
|
@@db.drop_index(@@coll.name, name)
|
332
326
|
end
|
data/test/grid_test.rb
CHANGED
@@ -42,6 +42,19 @@ class GridTest < Test::Unit::TestCase
|
|
42
42
|
assert_raise GridError do
|
43
43
|
@grid.get(@id)
|
44
44
|
end
|
45
|
+
assert_equal nil, @db['test-fs']['chunks'].find_one({:files_id => @id})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "Storing data with a length of zero" do
|
50
|
+
setup do
|
51
|
+
@grid = Grid.new(@db, 'test-fs')
|
52
|
+
@id = @grid.put('', 'sample', :metadata => {'app' => 'photos'})
|
53
|
+
end
|
54
|
+
|
55
|
+
should "return the zero length" do
|
56
|
+
data = @grid.get(@id)
|
57
|
+
assert_equal 0, data.read.length
|
45
58
|
end
|
46
59
|
end
|
47
60
|
|
@@ -12,7 +12,7 @@ class CollectionTest < Test::Unit::TestCase
|
|
12
12
|
@db = @conn['testing']
|
13
13
|
@coll = @db.collection('books')
|
14
14
|
@conn.expects(:send_message).with do |op, msg, log|
|
15
|
-
op == 2001 && log.include?("
|
15
|
+
op == 2001 && log.include?("testing['books'].update")
|
16
16
|
end
|
17
17
|
@coll.update({}, {:title => 'Moby Dick'})
|
18
18
|
end
|
@@ -22,11 +22,21 @@ class CollectionTest < Test::Unit::TestCase
|
|
22
22
|
@db = @conn['testing']
|
23
23
|
@coll = @db.collection('books')
|
24
24
|
@conn.expects(:send_message).with do |op, msg, log|
|
25
|
-
op == 2002 && log.include?("
|
25
|
+
op == 2002 && log.include?("testing['books'].insert")
|
26
26
|
end
|
27
27
|
@coll.insert({:title => 'Moby Dick'})
|
28
28
|
end
|
29
29
|
|
30
|
+
should "send sort data" do
|
31
|
+
@conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
|
32
|
+
@db = @conn['testing']
|
33
|
+
@coll = @db.collection('books')
|
34
|
+
@conn.expects(:receive_message).with do |op, msg, log, sock|
|
35
|
+
op == 2004 && log.include?("sort")
|
36
|
+
end.returns([[], 0, 0])
|
37
|
+
@coll.find({:title => 'Moby Dick'}).sort([['title', 1], ['author', 1]]).next_document
|
38
|
+
end
|
39
|
+
|
30
40
|
should "not log binary data" do
|
31
41
|
@conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
|
32
42
|
@db = @conn['testing']
|
@@ -43,7 +53,7 @@ class CollectionTest < Test::Unit::TestCase
|
|
43
53
|
@db = @conn['testing']
|
44
54
|
@coll = @db.collection('books')
|
45
55
|
@conn.expects(:send_message_with_safe_check).with do |op, msg, db_name, log|
|
46
|
-
op == 2001 && log.include?("
|
56
|
+
op == 2001 && log.include?("testing['books'].update")
|
47
57
|
end
|
48
58
|
@coll.update({}, {:title => 'Moby Dick'}, :safe => true)
|
49
59
|
end
|
@@ -53,7 +63,7 @@ class CollectionTest < Test::Unit::TestCase
|
|
53
63
|
@db = @conn['testing']
|
54
64
|
@coll = @db.collection('books')
|
55
65
|
@conn.expects(:send_message_with_safe_check).with do |op, msg, db_name, log|
|
56
|
-
op == 2001 && log.include?("
|
66
|
+
op == 2001 && log.include?("testing['books'].update")
|
57
67
|
end
|
58
68
|
@coll.update({}, {:title => 'Moby Dick'}, :safe => true)
|
59
69
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 19
|
8
|
+
- 2
|
9
|
+
version: 0.19.2
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Jim Menard
|
@@ -11,7 +16,7 @@ autorequire:
|
|
11
16
|
bindir: bin
|
12
17
|
cert_chain: []
|
13
18
|
|
14
|
-
date: 2010-
|
19
|
+
date: 2010-04-05 00:00:00 -04:00
|
15
20
|
default_executable:
|
16
21
|
dependencies: []
|
17
22
|
|
@@ -28,6 +33,18 @@ files:
|
|
28
33
|
- Rakefile
|
29
34
|
- mongo-ruby-driver.gemspec
|
30
35
|
- LICENSE.txt
|
36
|
+
- lib/bson/bson_c.rb
|
37
|
+
- lib/bson/bson_ruby.rb
|
38
|
+
- lib/bson/byte_buffer.rb
|
39
|
+
- lib/bson/exceptions.rb
|
40
|
+
- lib/bson/ordered_hash.rb
|
41
|
+
- lib/bson/types/binary.rb
|
42
|
+
- lib/bson/types/code.rb
|
43
|
+
- lib/bson/types/dbref.rb
|
44
|
+
- lib/bson/types/min_max_keys.rb
|
45
|
+
- lib/bson/types/objectid.rb
|
46
|
+
- lib/bson/types/regexp_of_holding.rb
|
47
|
+
- lib/bson.rb
|
31
48
|
- lib/mongo/collection.rb
|
32
49
|
- lib/mongo/connection.rb
|
33
50
|
- lib/mongo/cursor.rb
|
@@ -49,6 +66,7 @@ files:
|
|
49
66
|
- lib/mongo/util/bson_ruby.rb
|
50
67
|
- lib/mongo/util/byte_buffer.rb
|
51
68
|
- lib/mongo/util/conversions.rb
|
69
|
+
- lib/mongo/util/core_ext.rb
|
52
70
|
- lib/mongo/util/ordered_hash.rb
|
53
71
|
- lib/mongo/util/server_version.rb
|
54
72
|
- lib/mongo/util/support.rb
|
@@ -65,6 +83,7 @@ files:
|
|
65
83
|
- examples/types.rb
|
66
84
|
- bin/bson_benchmark.rb
|
67
85
|
- bin/fail_if_no_c.rb
|
86
|
+
- bin/gr.rb
|
68
87
|
has_rdoc: true
|
69
88
|
homepage: http://www.mongodb.org
|
70
89
|
licenses: []
|
@@ -80,22 +99,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
99
|
requirements:
|
81
100
|
- - ">="
|
82
101
|
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 0
|
83
104
|
version: "0"
|
84
|
-
version:
|
85
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
106
|
requirements:
|
87
107
|
- - ">="
|
88
108
|
- !ruby/object:Gem::Version
|
109
|
+
segments:
|
110
|
+
- 0
|
89
111
|
version: "0"
|
90
|
-
version:
|
91
112
|
requirements: []
|
92
113
|
|
93
114
|
rubyforge_project:
|
94
|
-
rubygems_version: 1.3.
|
115
|
+
rubygems_version: 1.3.6
|
95
116
|
signing_key:
|
96
117
|
specification_version: 3
|
97
118
|
summary: Ruby driver for the MongoDB
|
98
119
|
test_files:
|
120
|
+
- test/auxillary/1.4_features.rb
|
99
121
|
- test/auxillary/authentication_test.rb
|
100
122
|
- test/auxillary/autoreconnect_test.rb
|
101
123
|
- test/binary_test.rb
|