mongo 2.1.2 → 2.2.0.rc0

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.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +10 -3
  5. data/Rakefile +1 -7
  6. data/lib/csasl/csasl.bundle +0 -0
  7. data/lib/mongo/auth/user/view.rb +1 -1
  8. data/lib/mongo/bulk_write.rb +7 -1
  9. data/lib/mongo/client.rb +17 -15
  10. data/lib/mongo/cluster.rb +4 -2
  11. data/lib/mongo/collection.rb +36 -2
  12. data/lib/mongo/collection/view.rb +24 -21
  13. data/lib/mongo/collection/view/aggregation.rb +5 -42
  14. data/lib/mongo/collection/view/builder.rb +20 -0
  15. data/lib/mongo/collection/view/builder/aggregation.rb +98 -0
  16. data/lib/mongo/collection/view/builder/find_command.rb +111 -0
  17. data/lib/mongo/collection/view/builder/flags.rb +62 -0
  18. data/lib/mongo/collection/view/builder/map_reduce.rb +134 -0
  19. data/lib/mongo/collection/view/builder/modifiers.rb +80 -0
  20. data/lib/mongo/collection/view/builder/op_query.rb +83 -0
  21. data/lib/mongo/collection/view/explainable.rb +15 -0
  22. data/lib/mongo/collection/view/immutable.rb +5 -12
  23. data/lib/mongo/collection/view/iterable.rb +24 -2
  24. data/lib/mongo/collection/view/map_reduce.rb +18 -27
  25. data/lib/mongo/collection/view/readable.rb +70 -112
  26. data/lib/mongo/collection/view/writable.rb +23 -7
  27. data/lib/mongo/cursor.rb +76 -25
  28. data/lib/mongo/cursor/builder.rb +18 -0
  29. data/lib/mongo/cursor/builder/get_more_command.rb +71 -0
  30. data/lib/mongo/cursor/builder/kill_cursors_command.rb +62 -0
  31. data/lib/mongo/cursor/builder/op_get_more.rb +61 -0
  32. data/lib/mongo/cursor/builder/op_kill_cursors.rb +56 -0
  33. data/lib/mongo/database.rb +2 -2
  34. data/lib/mongo/database/view.rb +9 -5
  35. data/lib/mongo/dbref.rb +3 -3
  36. data/lib/mongo/error.rb +1 -0
  37. data/lib/mongo/error/invalid_write_concern.rb +35 -0
  38. data/lib/mongo/grid/file/chunk.rb +2 -2
  39. data/lib/mongo/index/view.rb +5 -2
  40. data/lib/mongo/operation.rb +1 -0
  41. data/lib/mongo/operation/commands.rb +2 -0
  42. data/lib/mongo/operation/commands/aggregate.rb +39 -45
  43. data/lib/mongo/operation/commands/aggregate/result.rb +54 -68
  44. data/lib/mongo/operation/commands/collections_info.rb +38 -36
  45. data/lib/mongo/operation/commands/collections_info/result.rb +17 -15
  46. data/lib/mongo/operation/commands/command.rb +24 -22
  47. data/lib/mongo/operation/commands/find.rb +27 -0
  48. data/lib/mongo/operation/commands/find/result.rb +62 -0
  49. data/lib/mongo/operation/commands/get_more.rb +27 -0
  50. data/lib/mongo/operation/commands/get_more/result.rb +62 -0
  51. data/lib/mongo/operation/commands/indexes.rb +41 -39
  52. data/lib/mongo/operation/commands/list_collections.rb +25 -31
  53. data/lib/mongo/operation/commands/list_collections/result.rb +63 -81
  54. data/lib/mongo/operation/commands/list_indexes.rb +27 -35
  55. data/lib/mongo/operation/commands/list_indexes/result.rb +67 -85
  56. data/lib/mongo/operation/commands/map_reduce.rb +29 -37
  57. data/lib/mongo/operation/commands/map_reduce/result.rb +85 -88
  58. data/lib/mongo/operation/commands/parallel_scan.rb +29 -33
  59. data/lib/mongo/operation/commands/parallel_scan/result.rb +34 -42
  60. data/lib/mongo/operation/commands/user_query.rb +40 -38
  61. data/lib/mongo/operation/commands/users_info.rb +24 -29
  62. data/lib/mongo/operation/commands/users_info/result.rb +13 -11
  63. data/lib/mongo/operation/object_id_generator.rb +36 -0
  64. data/lib/mongo/operation/result.rb +30 -0
  65. data/lib/mongo/operation/specifiable.rb +35 -1
  66. data/lib/mongo/operation/write/bulk/bulkable.rb +4 -3
  67. data/lib/mongo/operation/write/bulk/delete/result.rb +18 -25
  68. data/lib/mongo/operation/write/bulk/legacy_mergable.rb +2 -2
  69. data/lib/mongo/operation/write/command/delete.rb +3 -2
  70. data/lib/mongo/operation/write/command/insert.rb +4 -2
  71. data/lib/mongo/operation/write/command/update.rb +6 -3
  72. data/lib/mongo/operation/write/gle.rb +2 -1
  73. data/lib/mongo/operation/write/idable.rb +19 -2
  74. data/lib/mongo/options/mapper.rb +22 -0
  75. data/lib/mongo/protocol/bit_vector.rb +3 -3
  76. data/lib/mongo/protocol/delete.rb +15 -5
  77. data/lib/mongo/protocol/get_more.rb +10 -5
  78. data/lib/mongo/protocol/insert.rb +1 -6
  79. data/lib/mongo/protocol/kill_cursors.rb +14 -1
  80. data/lib/mongo/protocol/message.rb +32 -8
  81. data/lib/mongo/protocol/serializers.rb +15 -16
  82. data/lib/mongo/protocol/update.rb +35 -12
  83. data/lib/mongo/server/connectable.rb +3 -1
  84. data/lib/mongo/server/connection.rb +5 -5
  85. data/lib/mongo/server/description.rb +8 -2
  86. data/lib/mongo/server/description/features.rb +2 -1
  87. data/lib/mongo/server/monitor.rb +1 -12
  88. data/lib/mongo/server/monitor/connection.rb +30 -26
  89. data/lib/mongo/server_selector/selectable.rb +21 -4
  90. data/lib/mongo/uri.rb +2 -0
  91. data/lib/mongo/version.rb +1 -1
  92. data/lib/mongo/write_concern.rb +21 -6
  93. data/mongo.gemspec +1 -2
  94. data/spec/mongo/bulk_write/ordered_combiner_spec.rb +13 -0
  95. data/spec/mongo/bulk_write_spec.rb +58 -0
  96. data/spec/mongo/client_spec.rb +6 -4
  97. data/spec/mongo/collection/view/builder/find_command_spec.rb +167 -0
  98. data/spec/mongo/collection/view/builder/flags_spec.rb +106 -0
  99. data/spec/mongo/collection/view/builder/modifiers_spec.rb +210 -0
  100. data/spec/mongo/collection/view/builder/op_query_spec.rb +154 -0
  101. data/spec/mongo/collection/view/explainable_spec.rb +1 -2
  102. data/spec/mongo/collection/view/immutable_spec.rb +3 -52
  103. data/spec/mongo/collection/view/map_reduce_spec.rb +12 -12
  104. data/spec/mongo/collection/view/readable_spec.rb +86 -80
  105. data/spec/mongo/collection/view_spec.rb +109 -703
  106. data/spec/mongo/collection_spec.rb +594 -11
  107. data/spec/mongo/command_monitoring_spec.rb +40 -27
  108. data/spec/mongo/cursor/builder/get_more_command_spec.rb +160 -0
  109. data/spec/mongo/cursor/builder/op_get_more_spec.rb +52 -0
  110. data/spec/mongo/cursor_spec.rb +10 -60
  111. data/spec/mongo/database_spec.rb +24 -3
  112. data/spec/mongo/dbref_spec.rb +4 -4
  113. data/spec/mongo/grid/file/chunk_spec.rb +1 -1
  114. data/spec/mongo/grid/fs_bucket_spec.rb +3 -3
  115. data/spec/mongo/index/view_spec.rb +41 -0
  116. data/spec/mongo/operation/{aggregate → commands/aggregate}/result_spec.rb +1 -1
  117. data/spec/mongo/operation/commands/aggregate_spec.rb +1 -1
  118. data/spec/mongo/operation/commands/collections_info_spec.rb +1 -1
  119. data/spec/mongo/operation/commands/command_spec.rb +1 -1
  120. data/spec/mongo/operation/commands/indexes_spec.rb +1 -1
  121. data/spec/mongo/operation/commands/map_reduce_spec.rb +1 -1
  122. data/spec/mongo/operation/write/command/delete_spec.rb +25 -0
  123. data/spec/mongo/operation/write/command/insert_spec.rb +25 -0
  124. data/spec/mongo/operation/write/command/update_spec.rb +25 -0
  125. data/spec/mongo/protocol/delete_spec.rb +4 -4
  126. data/spec/mongo/protocol/get_more_spec.rb +4 -4
  127. data/spec/mongo/protocol/insert_spec.rb +3 -3
  128. data/spec/mongo/protocol/kill_cursors_spec.rb +3 -3
  129. data/spec/mongo/protocol/query_spec.rb +7 -7
  130. data/spec/mongo/protocol/update_spec.rb +5 -5
  131. data/spec/mongo/server/description/features_spec.rb +25 -0
  132. data/spec/mongo/write_concern_spec.rb +126 -0
  133. data/spec/spec_helper.rb +9 -19
  134. data/spec/support/command_monitoring.rb +8 -0
  135. data/spec/support/command_monitoring/find.yml +53 -4
  136. data/spec/support/matchers.rb +1 -1
  137. data/spec/support/shared/protocol.rb +5 -5
  138. data/spec/support/travis.rb +1 -1
  139. metadata +43 -10
  140. metadata.gz.sig +0 -0
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mongo::Collection::View::Builder::Flags do
4
+
5
+ describe '.map_flags' do
6
+
7
+ shared_examples_for 'a flag mapper' do
8
+
9
+ let(:flags) do
10
+ described_class.map_flags(options)
11
+ end
12
+
13
+ it 'maps allow partial results' do
14
+ expect(flags).to include(:partial)
15
+ end
16
+
17
+ it 'maps oplog replay' do
18
+ expect(flags).to include(:oplog_replay)
19
+ end
20
+
21
+ it 'maps no cursor timeout' do
22
+ expect(flags).to include(:no_cursor_timeout)
23
+ end
24
+
25
+ it 'maps tailable' do
26
+ expect(flags).to include(:tailable_cursor)
27
+ end
28
+
29
+ it 'maps await data' do
30
+ expect(flags).to include(:await_data)
31
+ end
32
+
33
+ it 'maps exhaust' do
34
+ expect(flags).to include(:exhaust)
35
+ end
36
+ end
37
+
38
+ context 'when the options are standard' do
39
+
40
+ let(:options) do
41
+ {
42
+ :allow_partial_results => true,
43
+ :oplog_replay => true,
44
+ :no_cursor_timeout => true,
45
+ :tailable => true,
46
+ :await_data => true,
47
+ :exhaust => true
48
+ }
49
+ end
50
+
51
+ it_behaves_like 'a flag mapper'
52
+ end
53
+
54
+ context 'when the options already have flags' do
55
+
56
+ let(:options) do
57
+ {
58
+ :flags => [
59
+ :partial,
60
+ :oplog_replay,
61
+ :no_cursor_timeout,
62
+ :tailable_cursor,
63
+ :await_data,
64
+ :exhaust
65
+ ]
66
+ }
67
+ end
68
+
69
+ it_behaves_like 'a flag mapper'
70
+ end
71
+
72
+ context 'when the options include tailable_await' do
73
+
74
+ let(:options) do
75
+ { :tailable_await => true }
76
+ end
77
+
78
+ let(:flags) do
79
+ described_class.map_flags(options)
80
+ end
81
+
82
+ it 'maps the await data option' do
83
+ expect(flags).to include(:await_data)
84
+ end
85
+
86
+ it 'maps the tailable option' do
87
+ expect(flags).to include(:tailable_cursor)
88
+ end
89
+ end
90
+
91
+ context 'when the options provide a cursor type' do
92
+
93
+ let(:options) do
94
+ { :cursor_type => :await_data }
95
+ end
96
+
97
+ let(:flags) do
98
+ described_class.map_flags(options)
99
+ end
100
+
101
+ it 'maps the cursor type to a flag' do
102
+ expect(flags).to include(:await_data)
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,210 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mongo::Collection::View::Builder::Modifiers do
4
+
5
+ describe '.map_driver_options' do
6
+
7
+ shared_examples_for 'transformable driver options' do
8
+
9
+ it 'maps hint' do
10
+ expect(transformed[:hint]).to eq("_id" => 1)
11
+ end
12
+
13
+ it 'maps comment' do
14
+ expect(transformed[:comment]).to eq('testing')
15
+ end
16
+
17
+ it 'maps max scan' do
18
+ expect(transformed[:max_scan]).to eq(200)
19
+ end
20
+
21
+ it 'maps max time ms' do
22
+ expect(transformed[:max_time_ms]).to eq(500)
23
+ end
24
+
25
+ it 'maps max' do
26
+ expect(transformed[:max_value]).to eq("name" => 'joe')
27
+ end
28
+
29
+ it 'maps min' do
30
+ expect(transformed[:min_value]).to eq("name" => 'albert')
31
+ end
32
+
33
+ it 'maps return key' do
34
+ expect(transformed[:return_key]).to be true
35
+ end
36
+
37
+ it 'maps show record id' do
38
+ expect(transformed[:show_disk_loc]).to be true
39
+ end
40
+
41
+ it 'maps snapshot' do
42
+ expect(transformed[:snapshot]).to be true
43
+ end
44
+
45
+ it 'maps explain' do
46
+ expect(transformed[:explain]).to be true
47
+ end
48
+
49
+ it 'returns a BSON document' do
50
+ expect(transformed).to be_a(BSON::Document)
51
+ end
52
+ end
53
+
54
+ context 'when the keys are strings' do
55
+
56
+ let(:modifiers) do
57
+ {
58
+ '$orderby' => { name: 1 },
59
+ '$hint' => { _id: 1 },
60
+ '$comment' => 'testing',
61
+ '$snapshot' => true,
62
+ '$maxScan' => 200,
63
+ '$max' => { name: 'joe' },
64
+ '$min' => { name: 'albert' },
65
+ '$maxTimeMS' => 500,
66
+ '$returnKey' => true,
67
+ '$showDiskLoc' => true,
68
+ '$explain' => true
69
+ }
70
+ end
71
+
72
+ let(:transformed) do
73
+ described_class.map_driver_options(modifiers)
74
+ end
75
+
76
+ it_behaves_like 'transformable driver options'
77
+ end
78
+
79
+ context 'when the keys are symbols' do
80
+
81
+ let(:modifiers) do
82
+ {
83
+ :$orderby => { name: 1 },
84
+ :$hint => { _id: 1 },
85
+ :$comment => 'testing',
86
+ :$snapshot => true,
87
+ :$maxScan => 200,
88
+ :$max => { name: 'joe' },
89
+ :$min => { name: 'albert' },
90
+ :$maxTimeMS => 500,
91
+ :$returnKey => true,
92
+ :$showDiskLoc => true,
93
+ :$explain => true
94
+ }
95
+ end
96
+
97
+ let(:transformed) do
98
+ described_class.map_driver_options(modifiers)
99
+ end
100
+
101
+ it_behaves_like 'transformable driver options'
102
+ end
103
+ end
104
+
105
+ describe '.map_server_modifiers' do
106
+
107
+ shared_examples_for 'transformable server modifiers' do
108
+
109
+ it 'maps hint' do
110
+ expect(transformed[:$hint]).to eq("_id" => 1)
111
+ end
112
+
113
+ it 'maps comment' do
114
+ expect(transformed[:$comment]).to eq('testing')
115
+ end
116
+
117
+ it 'maps max scan' do
118
+ expect(transformed[:$maxScan]).to eq(200)
119
+ end
120
+
121
+ it 'maps max time ms' do
122
+ expect(transformed[:$maxTimeMS]).to eq(500)
123
+ end
124
+
125
+ it 'maps max' do
126
+ expect(transformed[:$max]).to eq("name" => 'joe')
127
+ end
128
+
129
+ it 'maps min' do
130
+ expect(transformed[:$min]).to eq("name" => 'albert')
131
+ end
132
+
133
+ it 'maps return key' do
134
+ expect(transformed[:$returnKey]).to be true
135
+ end
136
+
137
+ it 'maps show record id' do
138
+ expect(transformed[:$showDiskLoc]).to be true
139
+ end
140
+
141
+ it 'maps snapshot' do
142
+ expect(transformed[:$snapshot]).to be true
143
+ end
144
+
145
+ it 'maps explain' do
146
+ expect(transformed[:$explain]).to be true
147
+ end
148
+
149
+ it 'returns a BSON document' do
150
+ expect(transformed).to be_a(BSON::Document)
151
+ end
152
+
153
+ it 'does not include non modifiers' do
154
+ expect(transformed[:limit]).to be_nil
155
+ end
156
+ end
157
+
158
+ context 'when the keys are strings' do
159
+
160
+ let(:options) do
161
+ {
162
+ 'sort' => { name: 1 },
163
+ 'hint' => { _id: 1 },
164
+ 'comment' => 'testing',
165
+ 'snapshot' => true,
166
+ 'max_scan' => 200,
167
+ 'max_value' => { name: 'joe' },
168
+ 'min_value' => { name: 'albert' },
169
+ 'max_time_ms' => 500,
170
+ 'return_key' => true,
171
+ 'show_disk_loc' => true,
172
+ 'explain' => true,
173
+ 'limit' => 10
174
+ }
175
+ end
176
+
177
+ let(:transformed) do
178
+ described_class.map_server_modifiers(options)
179
+ end
180
+
181
+ it_behaves_like 'transformable server modifiers'
182
+ end
183
+
184
+ context 'when the keys are symbols' do
185
+
186
+ let(:options) do
187
+ {
188
+ :sort => { name: 1 },
189
+ :hint => { _id: 1 },
190
+ :comment => 'testing',
191
+ :snapshot => true,
192
+ :max_scan => 200,
193
+ :max_value => { name: 'joe' },
194
+ :min_value => { name: 'albert' },
195
+ :max_time_ms => 500,
196
+ :return_key => true,
197
+ :show_disk_loc => true,
198
+ :explain => true,
199
+ :limit => 10
200
+ }
201
+ end
202
+
203
+ let(:transformed) do
204
+ described_class.map_server_modifiers(options)
205
+ end
206
+
207
+ it_behaves_like 'transformable server modifiers'
208
+ end
209
+ end
210
+ end
@@ -0,0 +1,154 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mongo::Collection::View::Builder::OpQuery do
4
+
5
+ describe '#specification' do
6
+
7
+ let(:filter) do
8
+ { 'name' => 'test' }
9
+ end
10
+
11
+ let(:builder) do
12
+ described_class.new(view)
13
+ end
14
+
15
+ let(:specification) do
16
+ builder.specification
17
+ end
18
+
19
+ let(:view) do
20
+ Mongo::Collection::View.new(authorized_collection, filter, options)
21
+ end
22
+
23
+ context 'when there are modifiers in the options' do
24
+
25
+ let(:options) do
26
+ {
27
+ sort: { _id: 1 },
28
+ projection: { name: 1 },
29
+ hint: { name: 1 },
30
+ skip: 10,
31
+ limit: 20,
32
+ batch_size: 5,
33
+ single_batch: false,
34
+ comment: "testing",
35
+ max_scan: 200,
36
+ max_time_ms: 40,
37
+ max_value: { name: 'joe' },
38
+ min_value: { name: 'albert' },
39
+ return_key: true,
40
+ show_disk_loc: true,
41
+ snapshot: true,
42
+ tailable: true,
43
+ oplog_replay: true,
44
+ no_cursor_timeout: true,
45
+ tailable_await: true,
46
+ allow_partial_results: true,
47
+ read_concern: { level: 'local' }
48
+ }
49
+ end
50
+
51
+ let(:selector) do
52
+ specification[:selector]
53
+ end
54
+
55
+ let(:opts) do
56
+ specification[:options]
57
+ end
58
+
59
+ let(:flags) do
60
+ opts[:flags]
61
+ end
62
+
63
+ it 'maps the collection name' do
64
+ expect(specification[:coll_name]).to eq(authorized_collection.name)
65
+ end
66
+
67
+ it 'maps the filter' do
68
+ expect(selector['$query']).to eq(filter)
69
+ end
70
+
71
+ it 'maps sort' do
72
+ expect(selector['$orderby']).to eq('_id' => 1)
73
+ end
74
+
75
+ it 'maps projection' do
76
+ expect(opts['project']).to eq('name' => 1)
77
+ end
78
+
79
+ it 'maps hint' do
80
+ expect(selector['$hint']).to eq('name' => 1)
81
+ end
82
+
83
+ it 'maps skip' do
84
+ expect(opts['skip']).to eq(10)
85
+ end
86
+
87
+ it 'maps limit' do
88
+ expect(opts['limit']).to eq(20)
89
+ end
90
+
91
+ it 'maps batch size' do
92
+ expect(opts['batch_size']).to eq(5)
93
+ end
94
+
95
+ it 'maps comment' do
96
+ expect(selector['$comment']).to eq('testing')
97
+ end
98
+
99
+ it 'maps max scan' do
100
+ expect(selector['$maxScan']).to eq(200)
101
+ end
102
+
103
+ it 'maps max time ms' do
104
+ expect(selector['$maxTimeMS']).to eq(40)
105
+ end
106
+
107
+ it 'maps max' do
108
+ expect(selector['$max']).to eq('name' => 'joe')
109
+ end
110
+
111
+ it 'maps min' do
112
+ expect(selector['$min']).to eq('name' => 'albert')
113
+ end
114
+
115
+ it 'does not map read concern' do
116
+ expect(selector['$readConcern']).to be_nil
117
+ expect(selector['readConcern']).to be_nil
118
+ expect(opts['readConcern']).to be_nil
119
+ end
120
+
121
+ it 'maps return key' do
122
+ expect(selector['$returnKey']).to be true
123
+ end
124
+
125
+ it 'maps show record id' do
126
+ expect(selector['$showDiskLoc']).to be true
127
+ end
128
+
129
+ it 'maps snapshot' do
130
+ expect(selector['$snapshot']).to be true
131
+ end
132
+
133
+ it 'maps tailable' do
134
+ expect(flags).to include(:tailable_cursor)
135
+ end
136
+
137
+ it 'maps oplog replay' do
138
+ expect(flags).to include(:oplog_replay)
139
+ end
140
+
141
+ it 'maps no cursor timeout' do
142
+ expect(flags).to include(:no_cursor_timeout)
143
+ end
144
+
145
+ it 'maps await data' do
146
+ expect(flags).to include(:await_data)
147
+ end
148
+
149
+ it 'maps allow partial results' do
150
+ expect(flags).to include(:partial)
151
+ end
152
+ end
153
+ end
154
+ end