mongo 2.0.6 → 2.1.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mongo.rb +2 -0
- data/lib/mongo/bulk_write.rb +1 -0
- data/lib/mongo/bulk_write/bulk_writable.rb +87 -31
- data/lib/mongo/bulk_write/deletable.rb +8 -7
- data/lib/mongo/bulk_write/insertable.rb +4 -3
- data/lib/mongo/bulk_write/ordered_bulk_write.rb +6 -6
- data/lib/mongo/bulk_write/replacable.rb +4 -3
- data/lib/mongo/bulk_write/result.rb +138 -0
- data/lib/mongo/bulk_write/unordered_bulk_write.rb +5 -8
- data/lib/mongo/bulk_write/updatable.rb +8 -7
- data/lib/mongo/client.rb +36 -4
- data/lib/mongo/cluster.rb +39 -4
- data/lib/mongo/cluster/topology/replica_set.rb +20 -4
- data/lib/mongo/cluster/topology/sharded.rb +1 -1
- data/lib/mongo/collection.rb +282 -29
- data/lib/mongo/collection/view/aggregation.rb +32 -4
- data/lib/mongo/collection/view/iterable.rb +2 -1
- data/lib/mongo/collection/view/map_reduce.rb +3 -1
- data/lib/mongo/collection/view/readable.rb +89 -14
- data/lib/mongo/collection/view/writable.rb +11 -5
- data/lib/mongo/cursor.rb +11 -3
- data/lib/mongo/dbref.rb +113 -0
- data/lib/mongo/error.rb +6 -2
- data/lib/mongo/error/parser.rb +1 -1
- data/lib/mongo/event/description_changed.rb +1 -1
- data/lib/mongo/grid/file.rb +1 -1
- data/lib/mongo/grid/fs.rb +2 -5
- data/lib/mongo/monitoring.rb +199 -0
- data/lib/mongo/monitoring/command_log_subscriber.rb +88 -0
- data/lib/mongo/monitoring/event.rb +17 -0
- data/lib/mongo/monitoring/event/command_failed.rb +96 -0
- data/lib/mongo/monitoring/event/command_started.rb +88 -0
- data/lib/mongo/monitoring/event/command_succeeded.rb +96 -0
- data/lib/mongo/monitoring/publishable.rb +96 -0
- data/lib/mongo/operation.rb +1 -0
- data/lib/mongo/operation/executable.rb +1 -1
- data/lib/mongo/operation/parallel_scan.rb +76 -0
- data/lib/mongo/operation/parallel_scan/result.rb +72 -0
- data/lib/mongo/operation/specifiable.rb +18 -0
- data/lib/mongo/operation/write/bulk/bulk_delete.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulk_insert.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulk_mergable.rb +2 -2
- data/lib/mongo/operation/write/bulk/bulk_update.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulk_update/result.rb +13 -1
- data/lib/mongo/protocol/delete.rb +8 -13
- data/lib/mongo/protocol/get_more.rb +13 -13
- data/lib/mongo/protocol/insert.rb +8 -13
- data/lib/mongo/protocol/kill_cursors.rb +7 -11
- data/lib/mongo/protocol/query.rb +58 -20
- data/lib/mongo/protocol/reply.rb +12 -0
- data/lib/mongo/protocol/update.rb +13 -14
- data/lib/mongo/server.rb +23 -2
- data/lib/mongo/server/connectable.rb +0 -22
- data/lib/mongo/server/connection.rb +29 -0
- data/lib/mongo/server/description.rb +23 -1
- data/lib/mongo/server/monitor.rb +17 -1
- data/lib/mongo/server/monitor/connection.rb +24 -0
- data/lib/mongo/socket/ssl.rb +28 -16
- data/lib/mongo/socket/tcp.rb +1 -1
- data/lib/mongo/socket/unix.rb +1 -1
- data/lib/mongo/uri.rb +12 -5
- data/lib/mongo/version.rb +1 -1
- data/spec/mongo/auth/cr_spec.rb +9 -1
- data/spec/mongo/auth/ldap_spec.rb +9 -1
- data/spec/mongo/auth/scram_spec.rb +9 -1
- data/spec/mongo/auth/x509_spec.rb +9 -1
- data/spec/mongo/{bulk/bulk_write_spec.rb → bulk_write_spec.rb} +15 -15
- data/spec/mongo/client_spec.rb +42 -0
- data/spec/mongo/cluster/topology/replica_set_spec.rb +16 -9
- data/spec/mongo/cluster/topology/sharded_spec.rb +11 -3
- data/spec/mongo/cluster/topology/single_spec.rb +12 -4
- data/spec/mongo/cluster_spec.rb +55 -10
- data/spec/mongo/collection/view/aggregation_spec.rb +123 -1
- data/spec/mongo/collection/view/explainable_spec.rb +1 -1
- data/spec/mongo/collection/view/map_reduce_spec.rb +1 -1
- data/spec/mongo/collection/view/readable_spec.rb +251 -6
- data/spec/mongo/collection/view/writable_spec.rb +4 -4
- data/spec/mongo/collection/view_spec.rb +233 -71
- data/spec/mongo/collection_spec.rb +905 -9
- data/spec/mongo/crud_spec.rb +2 -2
- data/spec/mongo/cursor_spec.rb +3 -3
- data/spec/mongo/dbref_spec.rb +149 -0
- data/spec/mongo/monitoring_spec.rb +168 -0
- data/spec/mongo/operation/map_reduce_spec.rb +1 -1
- data/spec/mongo/operation/write/bulk/bulk_delete_spec.rb +1 -1
- data/spec/mongo/operation/write/bulk/bulk_insert_spec.rb +2 -2
- data/spec/mongo/operation/write/bulk/bulk_update_spec.rb +1 -1
- data/spec/mongo/operation/write/delete_spec.rb +1 -1
- data/spec/mongo/operation/write/insert_spec.rb +2 -2
- data/spec/mongo/operation/write/update_spec.rb +1 -1
- data/spec/mongo/protocol/query_spec.rb +0 -29
- data/spec/mongo/server/connection_pool_spec.rb +18 -6
- data/spec/mongo/server/connection_spec.rb +12 -4
- data/spec/mongo/server/description_spec.rb +7 -3
- data/spec/mongo/server/monitor_spec.rb +30 -0
- data/spec/mongo/server_discovery_and_monitoring_spec.rb +11 -4
- data/spec/mongo/server_selection_spec.rb +14 -6
- data/spec/mongo/server_spec.rb +27 -8
- data/spec/mongo/socket/ssl_spec.rb +94 -8
- data/spec/mongo/uri_spec.rb +25 -9
- data/spec/spec_helper.rb +29 -20
- data/spec/support/authorization.rb +19 -4
- data/spec/support/certificates/client.pem +4 -4
- data/spec/support/crud/read.rb +9 -10
- data/spec/support/crud/write.rb +24 -20
- data/spec/support/sdam/rs/equal_electionids.yml +45 -0
- data/spec/support/sdam/rs/new_primary_new_electionid.yml +98 -0
- data/spec/support/sdam/rs/null_election_id.yml +144 -0
- data/spec/support/sdam/rs/primary_disconnect_electionid.yml +124 -0
- data/spec/support/sdam/sharded/mongos_disconnect.yml +104 -0
- data/spec/support/server_discovery_and_monitoring.rb +19 -2
- data/spec/support/shared/bulk_write.rb +26 -22
- data/spec/support/shared/server_selector.rb +2 -1
- metadata +31 -7
- metadata.gz.sig +0 -0
- data/lib/mongo/error/invalid_uri_option.rb +0 -38
data/spec/mongo/crud_spec.rb
CHANGED
@@ -13,11 +13,11 @@ describe 'CRUD' do
|
|
13
13
|
context(test.description) do
|
14
14
|
|
15
15
|
before(:each) do
|
16
|
-
authorized_collection.
|
16
|
+
authorized_collection.delete_many
|
17
17
|
end
|
18
18
|
|
19
19
|
after(:each) do
|
20
|
-
authorized_collection.
|
20
|
+
authorized_collection.delete_many
|
21
21
|
end
|
22
22
|
|
23
23
|
let(:results) do
|
data/spec/mongo/cursor_spec.rb
CHANGED
@@ -33,7 +33,7 @@ describe Mongo::Cursor do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
after do
|
36
|
-
authorized_collection.
|
36
|
+
authorized_collection.delete_many
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'returns the correct amount' do
|
@@ -58,7 +58,7 @@ describe Mongo::Cursor do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
after do
|
61
|
-
authorized_collection.
|
61
|
+
authorized_collection.delete_many
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'returns the correct amount' do
|
@@ -84,7 +84,7 @@ describe Mongo::Cursor do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
after do
|
87
|
-
authorized_collection.
|
87
|
+
authorized_collection.delete_many
|
88
88
|
end
|
89
89
|
|
90
90
|
context 'when a limit is provided' do
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
describe Mongo::DBRef do
|
5
|
+
|
6
|
+
let(:object_id) do
|
7
|
+
BSON::ObjectId.new
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#as_json' do
|
11
|
+
|
12
|
+
context 'when the database is not provided' do
|
13
|
+
|
14
|
+
let(:dbref) do
|
15
|
+
described_class.new('users', object_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns the json document without database' do
|
19
|
+
expect(dbref.as_json).to eq({ '$ref' => 'users', '$id' => object_id })
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when the database is provided' do
|
24
|
+
|
25
|
+
let(:dbref) do
|
26
|
+
described_class.new('users', object_id, 'database')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns the json document with database' do
|
30
|
+
expect(dbref.as_json).to eq({
|
31
|
+
'$ref' => 'users',
|
32
|
+
'$id' => object_id,
|
33
|
+
'$db' => 'database'
|
34
|
+
})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#initialize' do
|
40
|
+
|
41
|
+
let(:dbref) do
|
42
|
+
described_class.new('users', object_id)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'sets the collection' do
|
46
|
+
expect(dbref.collection).to eq('users')
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'sets the id' do
|
50
|
+
expect(dbref.id).to eq(object_id)
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when a database is provided' do
|
54
|
+
|
55
|
+
let(:dbref) do
|
56
|
+
described_class.new('users', object_id, 'db')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'sets the database' do
|
60
|
+
expect(dbref.database).to eq('db')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#to_bson' do
|
66
|
+
|
67
|
+
let(:dbref) do
|
68
|
+
described_class.new('users', object_id, 'database')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'converts the underlying document to bson' do
|
72
|
+
expect(dbref.to_bson).to eq(dbref.as_json.to_bson)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#to_json' do
|
77
|
+
|
78
|
+
context 'when the database is not provided' do
|
79
|
+
|
80
|
+
let(:dbref) do
|
81
|
+
described_class.new('users', object_id)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns the json document without database' do
|
85
|
+
expect(dbref.to_json).to eq("{\"$ref\":\"users\",\"$id\":#{object_id.to_json}}")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when the database is provided' do
|
90
|
+
|
91
|
+
let(:dbref) do
|
92
|
+
described_class.new('users', object_id, 'database')
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'returns the json document with database' do
|
96
|
+
expect(dbref.to_json).to eq("{\"$ref\":\"users\",\"$id\":#{object_id.to_json},\"$db\":\"database\"}")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#from_bson' do
|
102
|
+
|
103
|
+
let(:bson) do
|
104
|
+
StringIO.new(dbref.to_bson)
|
105
|
+
end
|
106
|
+
|
107
|
+
let(:decoded) do
|
108
|
+
BSON::Document.from_bson(bson)
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'when a database exists' do
|
112
|
+
|
113
|
+
let(:dbref) do
|
114
|
+
described_class.new('users', object_id, 'database')
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'decodes the ref' do
|
118
|
+
expect(decoded.collection).to eq('users')
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'decodes the id' do
|
122
|
+
expect(decoded.id).to eq(object_id)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'decodes the database' do
|
126
|
+
expect(decoded.database).to eq('database')
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'when no database exists' do
|
131
|
+
|
132
|
+
let(:dbref) do
|
133
|
+
described_class.new('users', object_id)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'decodes the ref' do
|
137
|
+
expect(decoded.collection).to eq('users')
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'decodes the id' do
|
141
|
+
expect(decoded.id).to eq(object_id)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'sets the database to nil' do
|
145
|
+
expect(decoded.database).to be_nil
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongo::Monitoring do
|
4
|
+
|
5
|
+
describe '#dup' do
|
6
|
+
|
7
|
+
let(:monitoring) do
|
8
|
+
described_class.new
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:copy) do
|
12
|
+
monitoring.dup
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'dups the subscribers' do
|
16
|
+
expect(monitoring.subscribers).to_not equal(copy.subscribers)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'keeps the same subscriber instances' do
|
20
|
+
expect(monitoring.subscribers).to eq(copy.subscribers)
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when adding to the copy' do
|
24
|
+
|
25
|
+
let(:subscriber) do
|
26
|
+
double('subscriber')
|
27
|
+
end
|
28
|
+
|
29
|
+
before do
|
30
|
+
copy.subscribe('topic', subscriber)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'does not modify the original subscribers' do
|
34
|
+
expect(monitoring.subscribers).to_not eq(copy.subscribers)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#initialize' do
|
40
|
+
|
41
|
+
context 'when no monitoring options provided' do
|
42
|
+
|
43
|
+
let(:monitoring) do
|
44
|
+
described_class.new
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'includes the global subscribers' do
|
48
|
+
expect(monitoring.subscribers.size).to eq(1)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when monitoring options provided' do
|
53
|
+
|
54
|
+
context 'when monitoring is true' do
|
55
|
+
|
56
|
+
let(:monitoring) do
|
57
|
+
described_class.new(monitoring: true)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'includes the global subscribers' do
|
61
|
+
expect(monitoring.subscribers.size).to eq(1)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when monitoring is false' do
|
66
|
+
|
67
|
+
let(:monitoring) do
|
68
|
+
described_class.new(monitoring: false)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'does not include the global subscribers' do
|
72
|
+
expect(monitoring.subscribers).to be_empty
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#subscribe' do
|
79
|
+
|
80
|
+
let(:monitoring) do
|
81
|
+
described_class.new(monitoring: false)
|
82
|
+
end
|
83
|
+
|
84
|
+
let(:subscriber) do
|
85
|
+
double('subscriber')
|
86
|
+
end
|
87
|
+
|
88
|
+
before do
|
89
|
+
monitoring.subscribe('topic', subscriber)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'subscribes to the topic' do
|
93
|
+
expect(monitoring.subscribers['topic']).to eq([ subscriber ])
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#started' do
|
98
|
+
|
99
|
+
let(:monitoring) do
|
100
|
+
described_class.new(monitoring: false)
|
101
|
+
end
|
102
|
+
|
103
|
+
let(:subscriber) do
|
104
|
+
double('subscriber')
|
105
|
+
end
|
106
|
+
|
107
|
+
let(:event) do
|
108
|
+
double('event')
|
109
|
+
end
|
110
|
+
|
111
|
+
before do
|
112
|
+
monitoring.subscribe('topic', subscriber)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'calls the started method on each subscriber' do
|
116
|
+
expect(subscriber).to receive(:started).with(event)
|
117
|
+
monitoring.started('topic', event)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '#succeeded' do
|
122
|
+
|
123
|
+
let(:monitoring) do
|
124
|
+
described_class.new(monitoring: false)
|
125
|
+
end
|
126
|
+
|
127
|
+
let(:subscriber) do
|
128
|
+
double('subscriber')
|
129
|
+
end
|
130
|
+
|
131
|
+
let(:event) do
|
132
|
+
double('event')
|
133
|
+
end
|
134
|
+
|
135
|
+
before do
|
136
|
+
monitoring.subscribe('topic', subscriber)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'calls the succeeded method on each subscriber' do
|
140
|
+
expect(subscriber).to receive(:succeeded).with(event)
|
141
|
+
monitoring.succeeded('topic', event)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe '#failed' do
|
146
|
+
|
147
|
+
let(:monitoring) do
|
148
|
+
described_class.new(monitoring: false)
|
149
|
+
end
|
150
|
+
|
151
|
+
let(:subscriber) do
|
152
|
+
double('subscriber')
|
153
|
+
end
|
154
|
+
|
155
|
+
let(:event) do
|
156
|
+
double('event')
|
157
|
+
end
|
158
|
+
|
159
|
+
before do
|
160
|
+
monitoring.subscribe('topic', subscriber)
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'calls the failed method on each subscriber' do
|
164
|
+
expect(subscriber).to receive(:failed).with(event)
|
165
|
+
monitoring.failed('topic', event)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -20,7 +20,7 @@ describe Mongo::Operation::Write::BulkInsert do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
after do
|
23
|
-
authorized_collection.
|
23
|
+
authorized_collection.delete_many
|
24
24
|
end
|
25
25
|
|
26
26
|
describe '#initialize' do
|
@@ -115,7 +115,7 @@ describe Mongo::Operation::Write::BulkInsert do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
after do
|
118
|
-
authorized_collection.
|
118
|
+
authorized_collection.delete_many
|
119
119
|
authorized_collection.indexes.drop_one('name_1')
|
120
120
|
end
|
121
121
|
|
@@ -16,7 +16,7 @@ describe Mongo::Operation::Write::Insert do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
after do
|
19
|
-
authorized_collection.
|
19
|
+
authorized_collection.delete_many
|
20
20
|
end
|
21
21
|
|
22
22
|
let(:insert) do
|
@@ -114,7 +114,7 @@ describe Mongo::Operation::Write::Insert do
|
|
114
114
|
end
|
115
115
|
|
116
116
|
after do
|
117
|
-
authorized_collection.
|
117
|
+
authorized_collection.delete_many
|
118
118
|
authorized_collection.indexes.drop_one('name_1')
|
119
119
|
end
|
120
120
|
|
@@ -282,33 +282,4 @@ describe Mongo::Protocol::Query do
|
|
282
282
|
end
|
283
283
|
end
|
284
284
|
end
|
285
|
-
|
286
|
-
describe '#log_message' do
|
287
|
-
|
288
|
-
context 'when the selector is greater than LOG_STRING_LIMIT characters' do
|
289
|
-
|
290
|
-
let(:selector) do
|
291
|
-
'z'*260
|
292
|
-
end
|
293
|
-
|
294
|
-
it 'Only prints LOG_STRING_LIMIT number of characters' do
|
295
|
-
expect(message.log_message.scan(/z/).length).to eq(Mongo::Protocol::Query::LOG_STRING_LIMIT)
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
context 'when the selector cannot be inspected' do
|
300
|
-
|
301
|
-
let(:selector) do
|
302
|
-
'invalid string'
|
303
|
-
end
|
304
|
-
|
305
|
-
before do
|
306
|
-
allow(selector).to receive(:inspect).and_raise(ArgumentError)
|
307
|
-
end
|
308
|
-
|
309
|
-
it 'Does not include the selector in the log message' do
|
310
|
-
expect(message.log_message.scan(/invalid string/).length).to eq(0)
|
311
|
-
end
|
312
|
-
end
|
313
|
-
end
|
314
285
|
end
|