mongo 2.5.1 → 2.5.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +3 -2
- data.tar.gz.sig +0 -0
- data/Rakefile +1 -1
- data/lib/mongo/auth/user/view.rb +4 -4
- data/lib/mongo/bulk_write.rb +14 -19
- data/lib/mongo/cluster.rb +4 -2
- data/lib/mongo/cluster/app_metadata.rb +1 -1
- data/lib/mongo/cluster/reapers/cursor_reaper.rb +1 -1
- data/lib/mongo/collection.rb +13 -13
- data/lib/mongo/collection/view.rb +2 -1
- data/lib/mongo/collection/view/aggregation.rb +1 -1
- data/lib/mongo/collection/view/change_stream.rb +1 -1
- data/lib/mongo/collection/view/iterable.rb +4 -4
- data/lib/mongo/collection/view/map_reduce.rb +3 -3
- data/lib/mongo/collection/view/readable.rb +26 -20
- data/lib/mongo/collection/view/writable.rb +12 -12
- data/lib/mongo/cursor.rb +4 -7
- data/lib/mongo/database.rb +2 -2
- data/lib/mongo/database/view.rb +1 -1
- data/lib/mongo/grid/stream/write.rb +1 -1
- data/lib/mongo/index/view.rb +3 -3
- data/lib/mongo/operation.rb +38 -24
- data/lib/mongo/operation/aggregate.rb +53 -0
- data/lib/mongo/operation/aggregate/command.rb +59 -0
- data/lib/mongo/operation/aggregate/op_msg.rb +54 -0
- data/lib/mongo/operation/aggregate/result.rb +87 -0
- data/lib/mongo/operation/collections_info.rb +62 -0
- data/lib/mongo/operation/collections_info/result.rb +39 -0
- data/lib/mongo/operation/{executable.rb → command.rb} +16 -13
- data/lib/mongo/operation/command/command.rb +38 -0
- data/lib/mongo/operation/command/op_msg.rb +53 -0
- data/lib/mongo/operation/count.rb +48 -0
- data/lib/mongo/operation/count/command.rb +38 -0
- data/lib/mongo/operation/count/op_msg.rb +38 -0
- data/lib/mongo/operation/create.rb +48 -0
- data/lib/mongo/operation/create/command.rb +38 -0
- data/lib/mongo/operation/create/op_msg.rb +37 -0
- data/lib/mongo/operation/create_index.rb +48 -0
- data/lib/mongo/operation/create_index/command.rb +42 -0
- data/lib/mongo/operation/create_index/op_msg.rb +41 -0
- data/lib/mongo/operation/create_user.rb +48 -0
- data/lib/mongo/operation/{commands → create_user}/command.rb +13 -19
- data/lib/mongo/operation/create_user/op_msg.rb +41 -0
- data/lib/mongo/operation/delete.rb +38 -0
- data/lib/mongo/operation/delete/bulk_result.rb +46 -0
- data/lib/mongo/operation/delete/command.rb +59 -0
- data/lib/mongo/operation/delete/legacy.rb +69 -0
- data/lib/mongo/operation/delete/op_msg.rb +60 -0
- data/lib/mongo/operation/{write/delete → delete}/result.rb +18 -16
- data/lib/mongo/operation/distinct.rb +48 -0
- data/lib/mongo/operation/distinct/command.rb +38 -0
- data/lib/mongo/operation/distinct/op_msg.rb +38 -0
- data/lib/mongo/operation/drop.rb +48 -0
- data/lib/mongo/operation/drop/command.rb +38 -0
- data/lib/mongo/operation/{commands/count.rb → drop/op_msg.rb} +16 -6
- data/lib/mongo/operation/drop_database.rb +48 -0
- data/lib/mongo/operation/drop_database/command.rb +38 -0
- data/lib/mongo/operation/drop_database/op_msg.rb +37 -0
- data/lib/mongo/operation/drop_index.rb +48 -0
- data/lib/mongo/operation/drop_index/command.rb +42 -0
- data/lib/mongo/operation/{limited.rb → drop_index/op_msg.rb} +19 -15
- data/lib/mongo/operation/explain.rb +52 -0
- data/lib/mongo/operation/explain/command.rb +54 -0
- data/lib/mongo/operation/explain/legacy.rb +53 -0
- data/lib/mongo/operation/explain/op_msg.rb +54 -0
- data/lib/mongo/operation/explain/result.rb +50 -0
- data/lib/mongo/operation/find.rb +52 -0
- data/lib/mongo/operation/find/command.rb +54 -0
- data/lib/mongo/operation/find/legacy.rb +55 -0
- data/lib/mongo/operation/{read/query → find/legacy}/result.rb +3 -3
- data/lib/mongo/operation/find/op_msg.rb +59 -0
- data/lib/mongo/operation/find/result.rb +60 -0
- data/lib/mongo/operation/{commands/users_info/result.rb → get_more.rb} +20 -22
- data/lib/mongo/operation/get_more/command.rb +54 -0
- data/lib/mongo/operation/{commands/find.rb → get_more/legacy.rb} +15 -8
- data/lib/mongo/operation/get_more/op_msg.rb +58 -0
- data/lib/mongo/operation/get_more/result.rb +60 -0
- data/lib/mongo/operation/indexes.rb +52 -0
- data/lib/mongo/operation/indexes/command.rb +54 -0
- data/lib/mongo/operation/indexes/legacy.rb +57 -0
- data/lib/mongo/operation/indexes/op_msg.rb +54 -0
- data/lib/mongo/operation/indexes/result.rb +97 -0
- data/lib/mongo/operation/insert.rb +40 -0
- data/lib/mongo/operation/insert/bulk_result.rb +70 -0
- data/lib/mongo/operation/insert/command.rb +65 -0
- data/lib/mongo/operation/insert/legacy.rb +72 -0
- data/lib/mongo/operation/insert/op_msg.rb +61 -0
- data/lib/mongo/operation/insert/result.rb +64 -0
- data/lib/mongo/operation/kill_cursors.rb +25 -14
- data/lib/mongo/operation/{takes_write_concern.rb → kill_cursors/command.rb} +14 -12
- data/lib/mongo/operation/kill_cursors/legacy.rb +37 -0
- data/lib/mongo/operation/kill_cursors/op_msg.rb +37 -0
- data/lib/mongo/operation/list_collections.rb +49 -0
- data/lib/mongo/operation/list_collections/command.rb +60 -0
- data/lib/mongo/operation/list_collections/op_msg.rb +53 -0
- data/lib/mongo/operation/list_collections/result.rb +92 -0
- data/lib/mongo/operation/map_reduce.rb +49 -0
- data/lib/mongo/operation/map_reduce/command.rb +55 -0
- data/lib/mongo/operation/map_reduce/op_msg.rb +54 -0
- data/lib/mongo/operation/map_reduce/result.rb +129 -0
- data/lib/mongo/operation/parallel_scan.rb +49 -0
- data/lib/mongo/operation/parallel_scan/command.rb +67 -0
- data/lib/mongo/operation/parallel_scan/op_msg.rb +61 -0
- data/lib/mongo/operation/parallel_scan/result.rb +61 -0
- data/lib/mongo/operation/remove_user.rb +48 -0
- data/lib/mongo/operation/remove_user/command.rb +42 -0
- data/lib/mongo/operation/remove_user/op_msg.rb +41 -0
- data/lib/mongo/operation/result.rb +3 -1
- data/lib/mongo/operation/shared/bypass_document_validation.rb +36 -0
- data/lib/mongo/operation/{causally_consistent.rb → shared/causal_consistency_supported.rb} +5 -5
- data/lib/mongo/operation/shared/executable.rb +45 -0
- data/lib/mongo/operation/shared/idable.rb +64 -0
- data/lib/mongo/operation/{commands/distinct.rb → shared/limited.rb} +10 -7
- data/lib/mongo/operation/{object_id_generator.rb → shared/object_id_generator.rb} +2 -2
- data/lib/mongo/operation/{read_preference.rb → shared/read_preference_supported.rb} +14 -24
- data/lib/mongo/operation/shared/result/aggregatable.rb +75 -0
- data/lib/mongo/operation/shared/sessions_supported.rb +79 -0
- data/lib/mongo/operation/{specifiable.rb → shared/specifiable.rb} +40 -4
- data/lib/mongo/operation/shared/write.rb +81 -0
- data/lib/mongo/operation/shared/write_concern_supported.rb +39 -0
- data/lib/mongo/operation/update.rb +38 -0
- data/lib/mongo/operation/update/bulk_result.rb +126 -0
- data/lib/mongo/operation/update/command.rb +60 -0
- data/lib/mongo/operation/update/legacy.rb +80 -0
- data/lib/mongo/operation/{write/update → update/legacy}/result.rb +4 -82
- data/lib/mongo/operation/update/op_msg.rb +60 -0
- data/lib/mongo/operation/update/result.rb +102 -0
- data/lib/mongo/operation/update_user.rb +48 -0
- data/lib/mongo/operation/update_user/command.rb +41 -0
- data/lib/mongo/operation/update_user/op_msg.rb +41 -0
- data/lib/mongo/operation/users_info.rb +49 -0
- data/lib/mongo/operation/users_info/command.rb +58 -0
- data/lib/mongo/operation/users_info/op_msg.rb +57 -0
- data/lib/mongo/operation/{commands/collections_info → users_info}/result.rb +18 -17
- data/lib/mongo/server.rb +3 -5
- data/lib/mongo/server/connectable.rb +3 -3
- data/lib/mongo/server/connection.rb +14 -0
- data/lib/mongo/server_selector.rb +1 -1
- data/lib/mongo/server_selector/selectable.rb +3 -12
- data/lib/mongo/session.rb +13 -1
- data/lib/mongo/session/session_pool.rb +1 -1
- data/lib/mongo/version.rb +1 -1
- data/spec/mongo/client_spec.rb +15 -22
- data/spec/mongo/cluster/app_metadata_spec.rb +19 -3
- data/spec/mongo/cluster/cursor_reaper_spec.rb +37 -0
- data/spec/mongo/cluster_spec.rb +2 -2
- data/spec/mongo/collection/view/change_stream_spec.rb +2 -2
- data/spec/mongo/collection_spec.rb +105 -14
- data/spec/mongo/cursor_spec.rb +11 -11
- data/spec/mongo/grid/fs_bucket_spec.rb +5 -0
- data/spec/mongo/max_staleness_spec.rb +3 -1
- data/spec/mongo/operation/{commands/aggregate → aggregate}/result_spec.rb +1 -1
- data/spec/mongo/operation/{commands/aggregate_spec.rb → aggregate_spec.rb} +1 -1
- data/spec/mongo/operation/{commands/collections_info_spec.rb → collections_info_spec.rb} +4 -2
- data/spec/mongo/operation/{commands/command_spec.rb → command_spec.rb} +1 -1
- data/spec/mongo/operation/{write/command/create_index_spec.rb → create_index_spec.rb} +1 -1
- data/spec/mongo/operation/{write/create_user_spec.rb → create_user_spec.rb} +1 -1
- data/spec/mongo/operation/{write/bulk/delete_spec.rb → delete/bulk_spec.rb} +8 -8
- data/spec/mongo/operation/delete/command_spec.rb +111 -0
- data/spec/mongo/operation/{write/command/delete_spec.rb → delete/op_msg_spec.rb} +40 -34
- data/spec/mongo/operation/{write/delete_spec.rb → delete_spec.rb} +7 -7
- data/spec/mongo/operation/{write/command/drop_index_spec.rb → drop_index_spec.rb} +1 -1
- data/spec/mongo/operation/{read/query_spec.rb → find/legacy_spec.rb} +2 -2
- data/spec/mongo/operation/{read/get_more_spec.rb → get_more_spec.rb} +3 -3
- data/spec/mongo/operation/{commands/indexes_spec.rb → indexes_spec.rb} +6 -4
- data/spec/mongo/operation/{write/bulk/insert_spec.rb → insert/bulk_spec.rb} +9 -9
- data/spec/mongo/operation/insert/command_spec.rb +110 -0
- data/spec/mongo/operation/{write/command/insert_spec.rb → insert/op_msg_spec.rb} +51 -41
- data/spec/mongo/operation/{write/insert_spec.rb → insert_spec.rb} +2 -2
- data/spec/mongo/operation/kill_cursors_spec.rb +2 -2
- data/spec/mongo/operation/limited_spec.rb +3 -3
- data/spec/mongo/operation/{commands/map_reduce_spec.rb → map_reduce_spec.rb} +1 -1
- data/spec/mongo/operation/read_preference_spec.rb +2 -2
- data/spec/mongo/operation/{write/command/remove_user_spec.rb → remove_user_spec.rb} +1 -1
- data/spec/mongo/operation/{write/bulk/update_spec.rb → update/bulk_spec.rb} +8 -8
- data/spec/mongo/operation/update/command_spec.rb +114 -0
- data/spec/mongo/operation/{write/command/update_spec.rb → update/op_msg_spec.rb} +49 -40
- data/spec/mongo/operation/{write/update_spec.rb → update_spec.rb} +6 -6
- data/spec/mongo/operation/{write/command/update_user_spec.rb → update_user_spec.rb} +1 -1
- data/spec/mongo/server/connection_spec.rb +0 -22
- data/spec/mongo/server_selector_spec.rb +55 -0
- data/spec/mongo/server_spec.rb +0 -42
- data/spec/mongo/session/session_pool_spec.rb +1 -1
- data/spec/mongo/uri/srv_protocol_spec.rb +2 -2
- data/spec/mongo/uri_spec.rb +2 -2
- data/spec/support/gridfs_tests/delete.yml +4 -38
- data/spec/support/gridfs_tests/download.yml +12 -30
- data/spec/support/server_selection.rb +1 -1
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_multiple.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_non_matching.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PossiblePrimary.yml +15 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PossiblePrimaryNearest.yml +15 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Primary.yml +0 -3
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred_non_matching.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred_non_matching.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_non_matching.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_multiple.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_non_matching.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Primary.yml +0 -3
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred_non_matching.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred_non_matching.yml +0 -1
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary_non_matching.yml +0 -1
- data/spec/support/server_selection/selection/Sharded/read/Nearest.yml +21 -0
- data/spec/support/server_selection/selection/Sharded/read/Primary.yml +19 -0
- data/spec/support/server_selection/selection/Sharded/read/PrimaryPreferred.yml +21 -0
- data/spec/support/server_selection/selection/Sharded/read/Secondary.yml +21 -0
- data/spec/support/server_selection/selection/Sharded/read/SecondaryPreferred.yml +0 -5
- data/spec/support/server_selection/selection/Single/read/SecondaryPreferred.yml +0 -1
- data/spec/support/server_selection/selection/Unknown/read/SecondaryPreferred.yml +0 -1
- data/spec/support/shared/session.rb +46 -5
- metadata +174 -116
- metadata.gz.sig +1 -2
- data/lib/mongo/operation/commands.rb +0 -31
- data/lib/mongo/operation/commands/aggregate.rb +0 -63
- data/lib/mongo/operation/commands/aggregate/result.rb +0 -89
- data/lib/mongo/operation/commands/collections_info.rb +0 -71
- data/lib/mongo/operation/commands/create.rb +0 -49
- data/lib/mongo/operation/commands/drop.rb +0 -49
- data/lib/mongo/operation/commands/drop_database.rb +0 -49
- data/lib/mongo/operation/commands/explain.rb +0 -27
- data/lib/mongo/operation/commands/explain/result.rb +0 -52
- data/lib/mongo/operation/commands/find/result.rb +0 -62
- data/lib/mongo/operation/commands/get_more.rb +0 -27
- data/lib/mongo/operation/commands/get_more/result.rb +0 -62
- data/lib/mongo/operation/commands/indexes.rb +0 -73
- data/lib/mongo/operation/commands/list_collections.rb +0 -48
- data/lib/mongo/operation/commands/list_collections/result.rb +0 -94
- data/lib/mongo/operation/commands/list_indexes.rb +0 -48
- data/lib/mongo/operation/commands/list_indexes/result.rb +0 -98
- data/lib/mongo/operation/commands/map_reduce.rb +0 -65
- data/lib/mongo/operation/commands/map_reduce/result.rb +0 -131
- data/lib/mongo/operation/commands/parallel_scan.rb +0 -54
- data/lib/mongo/operation/commands/parallel_scan/result.rb +0 -64
- data/lib/mongo/operation/commands/users_info.rb +0 -52
- data/lib/mongo/operation/read.rb +0 -16
- data/lib/mongo/operation/read/get_more.rb +0 -52
- data/lib/mongo/operation/read/query.rb +0 -55
- data/lib/mongo/operation/uses_command_op_msg.rb +0 -78
- data/lib/mongo/operation/write.rb +0 -22
- data/lib/mongo/operation/write/bulk.rb +0 -20
- data/lib/mongo/operation/write/bulk/bulkable.rb +0 -82
- data/lib/mongo/operation/write/bulk/delete.rb +0 -71
- data/lib/mongo/operation/write/bulk/delete/result.rb +0 -71
- data/lib/mongo/operation/write/bulk/insert.rb +0 -96
- data/lib/mongo/operation/write/bulk/insert/result.rb +0 -129
- data/lib/mongo/operation/write/bulk/legacy_mergable.rb +0 -87
- data/lib/mongo/operation/write/bulk/mergable.rb +0 -73
- data/lib/mongo/operation/write/bulk/update.rb +0 -81
- data/lib/mongo/operation/write/bulk/update/result.rb +0 -196
- data/lib/mongo/operation/write/command.rb +0 -23
- data/lib/mongo/operation/write/command/create_index.rb +0 -79
- data/lib/mongo/operation/write/command/create_user.rb +0 -61
- data/lib/mongo/operation/write/command/delete.rb +0 -79
- data/lib/mongo/operation/write/command/drop_index.rb +0 -80
- data/lib/mongo/operation/write/command/insert.rb +0 -69
- data/lib/mongo/operation/write/command/remove_user.rb +0 -60
- data/lib/mongo/operation/write/command/update.rb +0 -77
- data/lib/mongo/operation/write/command/update_user.rb +0 -61
- data/lib/mongo/operation/write/command/writable.rb +0 -70
- data/lib/mongo/operation/write/delete.rb +0 -75
- data/lib/mongo/operation/write/gle.rb +0 -49
- data/lib/mongo/operation/write/idable.rb +0 -63
- data/lib/mongo/operation/write/insert.rb +0 -74
- data/lib/mongo/operation/write/insert/result.rb +0 -62
- data/lib/mongo/operation/write/update.rb +0 -91
- data/lib/mongo/operation/write/write_command_enabled.rb +0 -77
data/lib/mongo/cursor.rb
CHANGED
@@ -206,10 +206,11 @@ module Mongo
|
|
206
206
|
|
207
207
|
def get_more_operation
|
208
208
|
if @server.features.find_command_enabled?
|
209
|
-
|
209
|
+
spec = Builder::GetMoreCommand.new(self, @session).specification
|
210
210
|
else
|
211
|
-
|
211
|
+
spec = Builder::OpGetMore.new(self).specification
|
212
212
|
end
|
213
|
+
Operation::GetMore.new(spec)
|
213
214
|
end
|
214
215
|
|
215
216
|
def kill_cursors
|
@@ -227,11 +228,7 @@ module Mongo
|
|
227
228
|
end
|
228
229
|
|
229
230
|
def kill_cursors_operation
|
230
|
-
|
231
|
-
Operation::Commands::Command.new(kill_cursors_op_spec)
|
232
|
-
else
|
233
|
-
Operation::KillCursors.new(kill_cursors_op_spec)
|
234
|
-
end
|
231
|
+
Operation::KillCursors.new(kill_cursors_op_spec)
|
235
232
|
end
|
236
233
|
|
237
234
|
def kill_cursors_op_spec
|
data/lib/mongo/database.rb
CHANGED
@@ -156,7 +156,7 @@ module Mongo
|
|
156
156
|
preference = ServerSelector.get(opts[:read] || ServerSelector::PRIMARY)
|
157
157
|
server = preference.select_server(cluster)
|
158
158
|
client.send(:with_session, opts) do |session|
|
159
|
-
Operation::
|
159
|
+
Operation::Command.new({
|
160
160
|
:selector => operation.dup,
|
161
161
|
:db_name => name,
|
162
162
|
:read => preference,
|
@@ -180,7 +180,7 @@ module Mongo
|
|
180
180
|
def drop(options = {})
|
181
181
|
operation = { :dropDatabase => 1 }
|
182
182
|
client.send(:with_session, options) do |session|
|
183
|
-
Operation::
|
183
|
+
Operation::DropDatabase.new({
|
184
184
|
selector: operation,
|
185
185
|
db_name: name,
|
186
186
|
write_concern: write_concern,
|
data/lib/mongo/database/view.rb
CHANGED
@@ -111,7 +111,7 @@ module Mongo
|
|
111
111
|
end
|
112
112
|
|
113
113
|
def initial_query_op(session)
|
114
|
-
Operation::
|
114
|
+
Operation::CollectionsInfo.new(collections_info_spec(session))
|
115
115
|
end
|
116
116
|
|
117
117
|
def send_initial_query(server, session)
|
data/lib/mongo/index/view.rb
CHANGED
@@ -157,7 +157,7 @@ module Mongo
|
|
157
157
|
session: session
|
158
158
|
}
|
159
159
|
spec[:write_concern] = write_concern if server.features.collation_enabled?
|
160
|
-
Operation::
|
160
|
+
Operation::CreateIndex.new(spec).execute(server)
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
@@ -232,7 +232,7 @@ module Mongo
|
|
232
232
|
}
|
233
233
|
server = next_primary
|
234
234
|
spec[:write_concern] = write_concern if server.features.collation_enabled?
|
235
|
-
Operation::
|
235
|
+
Operation::DropIndex.new(spec).execute(server)
|
236
236
|
end
|
237
237
|
end
|
238
238
|
|
@@ -251,7 +251,7 @@ module Mongo
|
|
251
251
|
end
|
252
252
|
|
253
253
|
def initial_query_op(session)
|
254
|
-
Operation::
|
254
|
+
Operation::Indexes.new(indexes_spec(session))
|
255
255
|
end
|
256
256
|
|
257
257
|
def limit; -1; end
|
data/lib/mongo/operation.rb
CHANGED
@@ -1,30 +1,44 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
require 'forwardable'
|
2
|
+
require 'mongo/operation/result'
|
3
|
+
|
4
|
+
require 'mongo/operation/shared/executable'
|
5
|
+
require 'mongo/operation/shared/read_preference_supported'
|
6
|
+
require 'mongo/operation/shared/bypass_document_validation'
|
7
|
+
require 'mongo/operation/shared/write_concern_supported'
|
8
|
+
require 'mongo/operation/shared/limited'
|
9
|
+
require 'mongo/operation/shared/sessions_supported'
|
10
|
+
require 'mongo/operation/shared/causal_consistency_supported'
|
11
|
+
require 'mongo/operation/shared/write'
|
12
|
+
require 'mongo/operation/shared/idable'
|
13
|
+
require 'mongo/operation/shared/specifiable'
|
14
|
+
require 'mongo/operation/shared/object_id_generator'
|
14
15
|
|
16
|
+
require 'mongo/operation/command'
|
17
|
+
require 'mongo/operation/aggregate'
|
15
18
|
require 'mongo/operation/result'
|
16
|
-
require 'mongo/operation/
|
17
|
-
require 'mongo/operation/
|
18
|
-
require 'mongo/operation/
|
19
|
-
require 'mongo/operation/
|
20
|
-
require 'mongo/operation/
|
21
|
-
require 'mongo/operation/
|
22
|
-
require 'mongo/operation/
|
23
|
-
require 'mongo/operation/
|
24
|
-
require 'mongo/operation/
|
25
|
-
require 'mongo/operation/
|
26
|
-
require 'mongo/operation/
|
19
|
+
require 'mongo/operation/collections_info'
|
20
|
+
require 'mongo/operation/list_collections'
|
21
|
+
require 'mongo/operation/update'
|
22
|
+
require 'mongo/operation/insert'
|
23
|
+
require 'mongo/operation/delete'
|
24
|
+
require 'mongo/operation/count'
|
25
|
+
require 'mongo/operation/distinct'
|
26
|
+
require 'mongo/operation/create'
|
27
|
+
require 'mongo/operation/drop'
|
28
|
+
require 'mongo/operation/drop_database'
|
29
|
+
require 'mongo/operation/get_more'
|
30
|
+
require 'mongo/operation/find'
|
31
|
+
require 'mongo/operation/explain'
|
27
32
|
require 'mongo/operation/kill_cursors'
|
33
|
+
require 'mongo/operation/indexes'
|
34
|
+
require 'mongo/operation/map_reduce'
|
35
|
+
require 'mongo/operation/users_info'
|
36
|
+
require 'mongo/operation/parallel_scan'
|
37
|
+
require 'mongo/operation/create_user'
|
38
|
+
require 'mongo/operation/update_user'
|
39
|
+
require 'mongo/operation/remove_user'
|
40
|
+
require 'mongo/operation/create_index'
|
41
|
+
require 'mongo/operation/drop_index'
|
28
42
|
|
29
43
|
module Mongo
|
30
44
|
module Operation
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Copyright (C) 2015-2018 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'mongo/operation/aggregate/command'
|
16
|
+
require 'mongo/operation/aggregate/op_msg'
|
17
|
+
require 'mongo/operation/aggregate/result'
|
18
|
+
|
19
|
+
module Mongo
|
20
|
+
module Operation
|
21
|
+
|
22
|
+
# A MongoDB aggregate operation.
|
23
|
+
#
|
24
|
+
# @note An aggregate operation can behave like a read and return a
|
25
|
+
# result set, or can behave like a write operation and
|
26
|
+
# output results to a user-specified collection.
|
27
|
+
#
|
28
|
+
# @api private
|
29
|
+
#
|
30
|
+
# @since 2.0.0
|
31
|
+
class Aggregate
|
32
|
+
include Specifiable
|
33
|
+
|
34
|
+
# Execute the operation.
|
35
|
+
#
|
36
|
+
# @example
|
37
|
+
# operation.execute(server)
|
38
|
+
#
|
39
|
+
# @param [ Mongo::Server ] server The server to send the operation to.
|
40
|
+
#
|
41
|
+
# @return [ Mongo::Operation::Aggregate::Result ] The operation result.
|
42
|
+
#
|
43
|
+
# @since 2.0.0
|
44
|
+
def execute(server)
|
45
|
+
if server.features.op_msg_enabled?
|
46
|
+
OpMsg.new(spec).execute(server)
|
47
|
+
else
|
48
|
+
Command.new(spec).execute(server)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Copyright (C) 2018 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
module Operation
|
17
|
+
class Aggregate
|
18
|
+
|
19
|
+
# A MongoDB aggregate operation sent as a command message.
|
20
|
+
#
|
21
|
+
# @api private
|
22
|
+
#
|
23
|
+
# @since 2.5.2
|
24
|
+
class Command
|
25
|
+
include Specifiable
|
26
|
+
include Executable
|
27
|
+
include ReadPreferenceSupported
|
28
|
+
include WriteConcernSupported
|
29
|
+
include Limited
|
30
|
+
|
31
|
+
# Execute the operation.
|
32
|
+
#
|
33
|
+
# @example
|
34
|
+
# operation.execute(server)
|
35
|
+
#
|
36
|
+
# @param [ Mongo::Server ] server The server to send the operation to.
|
37
|
+
#
|
38
|
+
# @return [ Mongo::Operation::Aggregate::Result ] The operation result.
|
39
|
+
#
|
40
|
+
# @since 2.5.2
|
41
|
+
def execute(server)
|
42
|
+
result = Result.new(dispatch_message(server))
|
43
|
+
process_result(result, server)
|
44
|
+
result.validate!
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def write_concern_supported?(server)
|
50
|
+
server.features.collation_enabled?
|
51
|
+
end
|
52
|
+
|
53
|
+
def message(server)
|
54
|
+
Protocol::Query.new(db_name, Database::COMMAND, command(server), options(server))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright (C) 2018 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
module Operation
|
17
|
+
class Aggregate
|
18
|
+
|
19
|
+
# A MongoDB aggregate operation sent as an op message.
|
20
|
+
#
|
21
|
+
# @api private
|
22
|
+
#
|
23
|
+
# @since 2.5.2
|
24
|
+
class OpMsg
|
25
|
+
include Specifiable
|
26
|
+
include Executable
|
27
|
+
include SessionsSupported
|
28
|
+
include CausalConsistencySupported
|
29
|
+
|
30
|
+
# Execute the operation.
|
31
|
+
#
|
32
|
+
# @example
|
33
|
+
# operation.execute(server)
|
34
|
+
#
|
35
|
+
# @param [ Mongo::Server ] server The server to send the operation to.
|
36
|
+
#
|
37
|
+
# @return [ Mongo::Operation::Aggregate::Result ] The operation result.
|
38
|
+
#
|
39
|
+
# @since 2.5.2
|
40
|
+
def execute(server)
|
41
|
+
result = Result.new(dispatch_message(server))
|
42
|
+
process_result(result, server)
|
43
|
+
result.validate!
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def message(server)
|
49
|
+
Protocol::Msg.new(flags, options, command(server))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# Copyright (C) 2014-2018 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
module Operation
|
17
|
+
|
18
|
+
# Aggregate result wrapper.
|
19
|
+
#
|
20
|
+
# @since 2.0.0
|
21
|
+
class Aggregate
|
22
|
+
|
23
|
+
# Defines custom behaviour of results in an aggregation context.
|
24
|
+
#
|
25
|
+
# @since 2.0.0
|
26
|
+
class Result < Operation::Result
|
27
|
+
|
28
|
+
# The field name for the aggregation explain information.
|
29
|
+
#
|
30
|
+
# @since 2.0.5
|
31
|
+
EXPLAIN = 'stages'.freeze
|
32
|
+
|
33
|
+
# The legacy field name for the aggregation explain information.
|
34
|
+
#
|
35
|
+
# @since 2.0.5
|
36
|
+
EXPLAIN_LEGACY = 'serverPipeline'.freeze
|
37
|
+
|
38
|
+
# Get the cursor id for the result.
|
39
|
+
#
|
40
|
+
# @example Get the cursor id.
|
41
|
+
# result.cursor_id
|
42
|
+
#
|
43
|
+
# @note Even though the wire protocol has a cursor_id field for all
|
44
|
+
# messages of type reply, it is always zero when using the
|
45
|
+
# aggregation framework and must be retrieved from the cursor
|
46
|
+
# document itself. Wahnsinn!
|
47
|
+
#
|
48
|
+
# @return [ Integer ] The cursor id.
|
49
|
+
#
|
50
|
+
# @since 2.0.0
|
51
|
+
def cursor_id
|
52
|
+
cursor_document ? cursor_document[CURSOR_ID] : 0
|
53
|
+
end
|
54
|
+
|
55
|
+
# Get the documents for the aggregation result. This is either the
|
56
|
+
# first document's 'result' field, or if a cursor option was selected
|
57
|
+
# it is the 'firstBatch' field in the 'cursor' field of the first
|
58
|
+
# document returned.
|
59
|
+
#
|
60
|
+
# @example Get the documents.
|
61
|
+
# result.documents
|
62
|
+
#
|
63
|
+
# @return [ Array<BSON::Document> ] The documents.
|
64
|
+
#
|
65
|
+
# @since 2.0.0
|
66
|
+
def documents
|
67
|
+
reply.documents[0][RESULT] || explain_document ||
|
68
|
+
cursor_document[FIRST_BATCH]
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def explain_document
|
74
|
+
first_document[EXPLAIN] || first_document[EXPLAIN_LEGACY]
|
75
|
+
end
|
76
|
+
|
77
|
+
def cursor_document
|
78
|
+
@cursor_document ||= reply.documents[0][CURSOR]
|
79
|
+
end
|
80
|
+
|
81
|
+
def first_document
|
82
|
+
@first_document ||= reply.documents[0]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Copyright (C) 2015-2018 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'mongo/operation/collections_info/result'
|
16
|
+
|
17
|
+
module Mongo
|
18
|
+
module Operation
|
19
|
+
|
20
|
+
# A MongoDB operation to get info on all collections in a given database.
|
21
|
+
#
|
22
|
+
# @api private
|
23
|
+
#
|
24
|
+
# @since 2.0.0
|
25
|
+
class CollectionsInfo
|
26
|
+
include Specifiable
|
27
|
+
include Executable
|
28
|
+
include ReadPreferenceSupported
|
29
|
+
|
30
|
+
# Execute the operation.
|
31
|
+
#
|
32
|
+
# @example
|
33
|
+
# operation.execute(server)
|
34
|
+
#
|
35
|
+
# @param [ Mongo::Server ] server The server to send the operation to.
|
36
|
+
#
|
37
|
+
# @return [ Mongo::Operation::CollectionsInfo::Result,
|
38
|
+
# Mongo::Operation::ListCollections::Result ] The operation result.
|
39
|
+
#
|
40
|
+
# @since 2.0.0
|
41
|
+
def execute(server)
|
42
|
+
if server.features.list_collections_enabled?
|
43
|
+
return Operation::ListCollections.new(spec).execute(server)
|
44
|
+
end
|
45
|
+
|
46
|
+
result = Result.new(dispatch_message(server))
|
47
|
+
process_result(result, server)
|
48
|
+
result.validate!
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def selector(server)
|
54
|
+
{ :name => { '$not' => /system\.|\$/ } }
|
55
|
+
end
|
56
|
+
|
57
|
+
def message(server)
|
58
|
+
Protocol::Query.new(db_name, Database::NAMESPACES, command(server), options(server))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|