mongo 2.0.0.beta → 2.0.0.rc

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +14 -1
  5. data/lib/mongo.rb +2 -1
  6. data/lib/mongo/auth.rb +2 -2
  7. data/lib/mongo/bulk_write.rb +52 -0
  8. data/lib/mongo/bulk_write/bulk_writable.rb +191 -0
  9. data/lib/mongo/bulk_write/deletable.rb +60 -0
  10. data/lib/mongo/bulk_write/insertable.rb +52 -0
  11. data/lib/mongo/bulk_write/ordered_bulk_write.rb +48 -0
  12. data/lib/mongo/bulk_write/replacable.rb +57 -0
  13. data/lib/mongo/bulk_write/unordered_bulk_write.rb +46 -0
  14. data/lib/mongo/bulk_write/updatable.rb +68 -0
  15. data/lib/mongo/client.rb +15 -2
  16. data/lib/mongo/cluster/topology/replica_set.rb +1 -1
  17. data/lib/mongo/cluster/topology/sharded.rb +1 -1
  18. data/lib/mongo/cluster/topology/standalone.rb +1 -1
  19. data/lib/mongo/cluster/topology/unknown.rb +1 -1
  20. data/lib/mongo/collection.rb +1 -1
  21. data/lib/mongo/collection/view/aggregation.rb +1 -1
  22. data/lib/mongo/collection/view/readable.rb +1 -1
  23. data/lib/mongo/collection/view/writable.rb +5 -5
  24. data/lib/mongo/cursor.rb +0 -2
  25. data/lib/mongo/error.rb +4 -3
  26. data/lib/mongo/error/{bulk_write_failure.rb → bulk_write_error.rb} +2 -2
  27. data/lib/mongo/error/invalid_bulk_operation.rb +2 -2
  28. data/lib/mongo/error/invalid_bulk_operation_type.rb +36 -0
  29. data/lib/mongo/error/{empty_batch.rb → multi_index_drop.rb} +5 -10
  30. data/lib/mongo/grid/file/metadata.rb +1 -8
  31. data/lib/mongo/grid/fs.rb +5 -5
  32. data/lib/mongo/index/view.rb +90 -34
  33. data/lib/mongo/operation.rb +0 -1
  34. data/lib/mongo/operation/aggregate.rb +2 -2
  35. data/lib/mongo/operation/aggregate/result.rb +4 -0
  36. data/lib/mongo/operation/bulk_delete/result.rb +2 -127
  37. data/lib/mongo/operation/bulk_insert/result.rb +2 -132
  38. data/lib/mongo/operation/bulk_update/result.rb +2 -142
  39. data/lib/mongo/operation/command.rb +1 -1
  40. data/lib/mongo/operation/executable.rb +3 -3
  41. data/lib/mongo/operation/list_collections/result.rb +0 -2
  42. data/lib/mongo/operation/map_reduce.rb +1 -1
  43. data/lib/mongo/operation/read/collections_info.rb +1 -1
  44. data/lib/mongo/operation/read/get_more.rb +1 -1
  45. data/lib/mongo/operation/read/indexes.rb +1 -1
  46. data/lib/mongo/operation/read/list_collections.rb +1 -1
  47. data/lib/mongo/operation/read/list_indexes.rb +1 -1
  48. data/lib/mongo/operation/read/query.rb +1 -1
  49. data/lib/mongo/operation/specifiable.rb +18 -1
  50. data/lib/mongo/operation/write.rb +2 -0
  51. data/lib/mongo/operation/write/bulk_delete.rb +5 -19
  52. data/lib/mongo/operation/write/bulk_insert.rb +9 -40
  53. data/lib/mongo/operation/write/bulk_mergable.rb +67 -0
  54. data/lib/mongo/operation/write/bulk_update.rb +5 -19
  55. data/lib/mongo/operation/write/command.rb +1 -1
  56. data/lib/mongo/operation/write/command/{ensure_index.rb → create_index.rb} +4 -9
  57. data/lib/mongo/operation/write/command/delete.rb +4 -4
  58. data/lib/mongo/operation/write/command/drop_index.rb +1 -1
  59. data/lib/mongo/operation/write/command/insert.rb +4 -4
  60. data/lib/mongo/operation/write/command/update.rb +4 -4
  61. data/lib/mongo/operation/write/create_index.rb +12 -7
  62. data/lib/mongo/operation/write/create_user.rb +1 -1
  63. data/lib/mongo/operation/write/delete.rb +1 -1
  64. data/lib/mongo/operation/write/drop_index.rb +1 -1
  65. data/lib/mongo/operation/write/insert.rb +1 -1
  66. data/lib/mongo/operation/write/legacy_bulk_mergable.rb +83 -0
  67. data/lib/mongo/operation/write/remove_user.rb +1 -1
  68. data/lib/mongo/operation/write/update.rb +1 -1
  69. data/lib/mongo/{bulk.rb → options.rb} +2 -2
  70. data/lib/mongo/options/mapper.rb +78 -0
  71. data/lib/mongo/server.rb +2 -2
  72. data/lib/mongo/server/connection_pool/queue.rb +1 -1
  73. data/lib/mongo/server/description.rb +1 -1
  74. data/lib/mongo/server/description/inspector.rb +1 -1
  75. data/lib/mongo/server_selector.rb +1 -1
  76. data/lib/mongo/socket/unix.rb +2 -4
  77. data/lib/mongo/version.rb +1 -1
  78. data/lib/mongo/write_concern/acknowledged.rb +15 -1
  79. data/lib/mongo/write_concern/normalizable.rb +0 -22
  80. data/lib/mongo/write_concern/unacknowledged.rb +12 -0
  81. data/spec/mongo/bulk/bulk_write_spec.rb +178 -91
  82. data/spec/mongo/collection/view/aggregation_spec.rb +14 -1
  83. data/spec/mongo/collection/view/explainable_spec.rb +1 -1
  84. data/spec/mongo/collection/view/map_reduce_spec.rb +2 -2
  85. data/spec/mongo/collection/view/readable_spec.rb +2 -2
  86. data/spec/mongo/collection/view/writable_spec.rb +7 -7
  87. data/spec/mongo/collection/view_spec.rb +14 -5
  88. data/spec/mongo/collection_spec.rb +5 -5
  89. data/spec/mongo/cursor_spec.rb +3 -3
  90. data/spec/mongo/database_spec.rb +4 -8
  91. data/spec/mongo/grid/fs_spec.rb +8 -8
  92. data/spec/mongo/index/view_spec.rb +139 -35
  93. data/spec/mongo/operation/aggregate_spec.rb +14 -22
  94. data/spec/mongo/operation/command_spec.rb +8 -16
  95. data/spec/mongo/operation/map_reduce_spec.rb +1 -1
  96. data/spec/mongo/operation/read/indexes_spec.rb +2 -2
  97. data/spec/mongo/operation/write/bulk_delete_spec.rb +1 -239
  98. data/spec/mongo/operation/write/bulk_insert_spec.rb +3 -234
  99. data/spec/mongo/operation/write/bulk_update_spec.rb +1 -289
  100. data/spec/mongo/operation/write/command/delete_spec.rb +0 -13
  101. data/spec/mongo/operation/write/command/insert_spec.rb +0 -14
  102. data/spec/mongo/operation/write/command/update_spec.rb +0 -14
  103. data/spec/mongo/operation/write/{ensure_index_spec.rb → create_index_spec.rb} +8 -26
  104. data/spec/mongo/operation/write/delete_spec.rb +1 -1
  105. data/spec/mongo/operation/write/drop_index_spec.rb +1 -1
  106. data/spec/mongo/operation/write/insert_spec.rb +3 -3
  107. data/spec/mongo/operation/write/update_spec.rb +1 -1
  108. data/spec/mongo/server_selection_spec.rb +2 -2
  109. data/spec/support/authorization.rb +4 -2
  110. data/spec/support/server_selection.rb +25 -8
  111. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest.yml +4 -10
  112. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_non_matching.yml +6 -12
  113. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Primary.yml +4 -6
  114. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred.yml +4 -10
  115. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred_non_matching.yml +6 -12
  116. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary.yml +4 -10
  117. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred.yml +4 -10
  118. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred_non_matching.yml +6 -12
  119. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_non_matching.yml +6 -12
  120. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest.yml +9 -17
  121. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_non_matching.yml +9 -17
  122. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Primary.yml +6 -10
  123. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred.yml +11 -21
  124. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred_non_matching.yml +11 -18
  125. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary.yml +31 -0
  126. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred.yml +31 -0
  127. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred_non_matching.yml +29 -0
  128. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary_non_matching.yml +26 -0
  129. data/spec/support/server_selection/selection/Sharded/read/SecondaryPreferred.yml +4 -10
  130. data/spec/support/server_selection/selection/Single/read/SecondaryPreferred.yml +2 -6
  131. data/spec/support/server_selection/selection/Unknown/read/SecondaryPreferred.yml +0 -2
  132. data/spec/support/shared/bulk_write.rb +109 -72
  133. metadata +29 -10
  134. metadata.gz.sig +0 -0
  135. data/lib/mongo/bulk/bulk_write.rb +0 -307
  136. data/lib/mongo/operation/batchable.rb +0 -103
@@ -0,0 +1,57 @@
1
+ # Copyright (C) 2014-2015 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 BulkWrite
17
+
18
+ # Defines behavior for validating and combining replace bulk write operations.
19
+ #
20
+ # @since 2.0.0.
21
+ module Replacable
22
+
23
+ private
24
+
25
+ def replacement_doc?(doc)
26
+ doc.respond_to?(:keys) && doc.keys.all?{|key| key !~ /^\$/}
27
+ end
28
+
29
+ def validate_replace_op!(r, type)
30
+ unless r[:find] && r[:replacement] && replacement_doc?(r[:replacement])
31
+ raise Error::InvalidBulkOperation.new(type, r)
32
+ end
33
+ end
34
+
35
+ def replace_ops(ops, type)
36
+ ops.collect do |r|
37
+ validate_replace_op!(r, type)
38
+ { q: r[:find],
39
+ u: r[:replacement],
40
+ multi: false,
41
+ upsert: r.fetch(:upsert, false)
42
+ }
43
+ end
44
+ end
45
+
46
+ def replace_one(op, server)
47
+ Operation::Write::BulkUpdate.new(
48
+ :updates => replace_ops(op[:replace_one], __method__),
49
+ :db_name => database.name,
50
+ :coll_name => @collection.name,
51
+ :write_concern => write_concern,
52
+ :ordered => ordered?
53
+ ).execute(server.context)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,46 @@
1
+ # Copyright (C) 2014-2015 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
+
17
+ module BulkWrite
18
+
19
+ class UnorderedBulkWrite
20
+
21
+ include BulkWritable
22
+
23
+ private
24
+
25
+ def ordered?
26
+ false
27
+ end
28
+
29
+ def merged_ops
30
+ merge_consecutive_ops(merge_ops_by_type)
31
+ end
32
+
33
+ def process(result, indexes)
34
+ combine_results(result, indexes)
35
+ end
36
+
37
+ def finalize
38
+ @results.tap do |results|
39
+ if results[:write_errors] || results[:write_concern_errors]
40
+ raise Error::BulkWriteError.new(results)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,68 @@
1
+ # Copyright (C) 2014-2015 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 BulkWrite
17
+
18
+ # Defines behavior for validating and combining update bulk write operations.
19
+ #
20
+ # @since 2.0.0.
21
+ module Updatable
22
+
23
+ private
24
+
25
+ def update_doc?(doc)
26
+ !doc.empty? &&
27
+ doc.respond_to?(:keys) &&
28
+ doc.keys.first.to_s =~ /^\$/
29
+ end
30
+
31
+ def validate_update_op!(type, u)
32
+ unless u[:find] && u[:update] && update_doc?(u[:update])
33
+ raise Error::InvalidBulkOperation.new(type, u)
34
+ end
35
+ end
36
+
37
+ def updates(ops, type)
38
+ multi = type == :update_many
39
+ ops.collect do |u|
40
+ validate_update_op!(type, u)
41
+ { q: u[:find],
42
+ u: u[:update],
43
+ multi: multi,
44
+ upsert: u.fetch(:upsert, false)
45
+ }
46
+ end
47
+ end
48
+
49
+ def update(ops, type, server)
50
+ Operation::Write::BulkUpdate.new(
51
+ :updates => updates(ops, type),
52
+ :db_name => database.name,
53
+ :coll_name => @collection.name,
54
+ :write_concern => write_concern,
55
+ :ordered => ordered?
56
+ ).execute(server.context)
57
+ end
58
+
59
+ def update_one(op, server)
60
+ update(op[:update_one], __method__, server)
61
+ end
62
+
63
+ def update_many(op, server)
64
+ update(op[:update_many], __method__, server)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -98,8 +98,10 @@ module Mongo
98
98
  # @option options [ Hash ] :auth_mech_properties
99
99
  # @option options [ Float ] :heartbeat_frequency The number of seconds for
100
100
  # the server monitor to refresh it's description via ismaster.
101
- # @option options [ Integer ] :local_threshold
102
- # @option options [ Integer ] :server_selection_timeout
101
+ # @option options [ Integer ] :local_threshold The local threshold boundary
102
+ # in seconds for selecting a near server for an operation.
103
+ # @option options [ Integer ] :server_selection_timeout The timeout in seconds
104
+ # for selecting a server for an operation.
103
105
  # @option options [ String ] :password The user's password.
104
106
  # @option options [ Integer ] :max_pool_size The maximum size of the
105
107
  # connection pool.
@@ -117,6 +119,17 @@ module Mongo
117
119
  # @option options [ Symbol ] :replica_set The name of the replica set to
118
120
  # connect to. Servers not in this replica set will be ignored.
119
121
  # @option options [ true, false ] :ssl Whether to use SSL.
122
+ # @option options [ String ] :ssl_cert The certificate file used to identify
123
+ # the connection against MongoDB.
124
+ # @option options [ String ] :ssl_key The private keyfile used to identify the
125
+ # connection against MongoDB. Note that even if the key is stored in the same
126
+ # file as the certificate, both need to be explicitly specified.
127
+ # @option options [ String ] :ssl_key_pass_phrase A passphrase for the private key.
128
+ # @option options [ true, false ] :ssl_verify Whether or not to do peer certification
129
+ # validation.
130
+ # @option options [ String ] :ssl_ca_cert The file containing a set of concatenated
131
+ # certification authority certifications used to validate certs passed from the
132
+ # other end of the connection. Required for :ssl_verify.
120
133
  # @option options [ Float ] :socket_timeout The timeout, in seconds, to
121
134
  # execute operations on a socket.
122
135
  # @option options [ String ] :user The user name.
@@ -54,7 +54,7 @@ module Mongo
54
54
  #
55
55
  # @param [ Server::Description ] description The description of the
56
56
  # elected primary.
57
- # @param [ Array<Server> ] server The list of known servers to the
57
+ # @param [ Array<Server> ] servers The list of known servers to the
58
58
  # cluster.
59
59
  #
60
60
  # @return [ ReplicaSet ] The topology.
@@ -45,7 +45,7 @@ module Mongo
45
45
  #
46
46
  # @param [ Server::Description ] description The description of the
47
47
  # elected primary.
48
- # @param [ Array<Server> ] server The list of known servers to the
48
+ # @param [ Array<Server> ] servers The list of known servers to the
49
49
  # cluster.
50
50
  #
51
51
  # @return [ Sharded ] The topology.
@@ -45,7 +45,7 @@ module Mongo
45
45
  #
46
46
  # @param [ Server::Description ] description The description of the
47
47
  # elected primary.
48
- # @param [ Array<Server> ] server The list of known servers to the
48
+ # @param [ Array<Server> ] servers The list of known servers to the
49
49
  # cluster.
50
50
  #
51
51
  # @return [ Standalone ] The topology.
@@ -49,7 +49,7 @@ module Mongo
49
49
  #
50
50
  # @param [ Server::Description ] description The description of the
51
51
  # elected primary.
52
- # @param [ Array<Server> ] server The list of known servers to the
52
+ # @param [ Array<Server> ] servers The list of known servers to the
53
53
  # cluster.
54
54
  #
55
55
  # @return [ Sharded, ReplicaSet ] The new topology.
@@ -203,7 +203,7 @@ module Mongo
203
203
  #
204
204
  # @since 2.0.0
205
205
  def bulk_write(operations, options)
206
- BulkWrite.new(operations, options, self).execute
206
+ BulkWrite.get(self, operations, options).execute
207
207
  end
208
208
 
209
209
  # Get the fully qualified namespace of the collection.
@@ -96,7 +96,7 @@ module Mongo
96
96
  def send_initial_query(server)
97
97
  begin
98
98
  initial_query_op.execute(server.context)
99
- rescue Mongo::Operation::Aggregate::NeedPrimaryServer
99
+ rescue Mongo::Error::NeedPrimaryServer
100
100
  warn 'Rerouting the Aggregation operation to the primary server.'
101
101
  server = ServerSelector.get(mode: :primary).select_server(cluster)
102
102
  initial_query_op.execute(server.context)
@@ -271,7 +271,7 @@ module Mongo
271
271
  # @example Set the number to skip.
272
272
  # view.skip(10)
273
273
  #
274
- # @param [ Integer ] skip Number of docs to skip.
274
+ # @param [ Integer ] number Number of docs to skip.
275
275
  #
276
276
  # @return [ Integer, View ] Either the skip value or a
277
277
  # new +View+.
@@ -45,7 +45,7 @@ module Mongo
45
45
  # @example Find a document and replace it, returning the new document.
46
46
  # view.find_one_and_replace({ name: 'test' }, :return_document => :after)
47
47
  #
48
- # @param [ BSON::Document ] document The updates.
48
+ # @param [ BSON::Document ] replacement The updates.
49
49
  # @param [ Hash ] opts The options.
50
50
  #
51
51
  # @option opts [ Symbol ] :return_document Either :before or :after.
@@ -85,24 +85,24 @@ module Mongo
85
85
  # Remove documents from the collection.
86
86
  #
87
87
  # @example Remove multiple documents from the collection.
88
- # collection_view.remove_many
88
+ # collection_view.delete_many
89
89
  #
90
90
  # @return [ Result ] The response from the database.
91
91
  #
92
92
  # @since 2.0.0
93
- def remove_many
93
+ def delete_many
94
94
  remove(0)
95
95
  end
96
96
 
97
97
  # Remove a document from the collection.
98
98
  #
99
99
  # @example Remove a single document from the collection.
100
- # collection_view.remove_one
100
+ # collection_view.delete_one
101
101
  #
102
102
  # @return [ Result ] The response from the database.
103
103
  #
104
104
  # @since 2.0.0
105
- def remove_one
105
+ def delete_one
106
106
  remove(1)
107
107
  end
108
108
 
@@ -71,8 +71,6 @@ module Mongo
71
71
  # ...
72
72
  # end
73
73
  #
74
- # @yield param [Hash] Each matching document.
75
- #
76
74
  # @return [ Enumerator ] The enumerator.
77
75
  #
78
76
  # @since 2.0.0
@@ -40,7 +40,7 @@ module Mongo
40
40
 
41
41
  # The constant for the writeErrors array.
42
42
  #
43
- # @sicne 2.0.0
43
+ # @since 2.0.0
44
44
  WRITE_ERRORS = 'writeErrors'.freeze
45
45
 
46
46
  # The constant for write concern errors.
@@ -61,10 +61,10 @@ module Mongo
61
61
  end
62
62
 
63
63
  require 'mongo/error/parser'
64
- require 'mongo/error/bulk_write_failure'
64
+ require 'mongo/error/bulk_write_error'
65
65
  require 'mongo/error/operation_failure'
66
- require 'mongo/error/empty_batch'
67
66
  require 'mongo/error/invalid_bulk_operation'
67
+ require 'mongo/error/invalid_bulk_operation_type'
68
68
  require 'mongo/error/invalid_collection_name'
69
69
  require 'mongo/error/invalid_database_name'
70
70
  require 'mongo/error/invalid_document'
@@ -75,6 +75,7 @@ require 'mongo/error/invalid_signature'
75
75
  require 'mongo/error/invalid_update_document'
76
76
  require 'mongo/error/max_bson_size'
77
77
  require 'mongo/error/max_message_size'
78
+ require 'mongo/error/multi_index_drop'
78
79
  require 'mongo/error/need_primary_server'
79
80
  require 'mongo/error/socket_error'
80
81
  require 'mongo/error/socket_timeout_error'
@@ -19,7 +19,7 @@ module Mongo
19
19
  # operation.
20
20
  #
21
21
  # @since 2.0.0
22
- class BulkWriteFailure < Error
22
+ class BulkWriteError < Error
23
23
 
24
24
  # @return [ BSON::Document ] result The error result.
25
25
  attr_reader :result
@@ -29,7 +29,7 @@ module Mongo
29
29
  # @example Instantiate the exception.
30
30
  # Mongo::Error::BulkWriteFailure.new(response)
31
31
  #
32
- # @params [ Hash ] result A processed response from the server
32
+ # @param [ Hash ] result A processed response from the server
33
33
  # reporting results of the operation.
34
34
  #
35
35
  # @since 2.0.0
@@ -28,8 +28,8 @@ module Mongo
28
28
  # @param [ String ] name The attempted operation name.
29
29
  #
30
30
  # @since 2.0.0
31
- def initialize(name)
32
- super("Invalid operation type: #{name}.")
31
+ def initialize(type, operation)
32
+ super("Invalid document format for bulk #{type} operation: #{operation}.")
33
33
  end
34
34
  end
35
35
  end
@@ -0,0 +1,36 @@
1
+ # Copyright (C) 2014-2015 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
+ class Error
17
+
18
+ # Exception raised if an non-existent operation type is used.
19
+ #
20
+ # @since 2.0.0
21
+ class InvalidBulkOperationType < Error
22
+
23
+ # Instantiate the new exception.
24
+ #
25
+ # @example Instantiate the exception.
26
+ # Mongo::Error::InvalidBulkOperationType.new(type)
27
+ #
28
+ # @param [ String ] type The attempted operation type.
29
+ #
30
+ # @since 2.0.0
31
+ def initialize(type)
32
+ super("Invalid bulk operation type: #{type}.")
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
1
+ # Copyright (C) 2015 MongoDB, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -15,24 +15,19 @@
15
15
  module Mongo
16
16
  class Error
17
17
 
18
- # Exception raised for bulk operations that are empty.
18
+ # Exception raised if '*' is passed to drop_one on indexes.
19
19
  #
20
20
  # @since 2.0.0
21
- class EmptyBatch < Error
22
-
23
- # The error message.
24
- #
25
- # @since 2.0.0
26
- MESSAGE = 'No operations to execute'.freeze
21
+ class MultiIndexDrop < Error
27
22
 
28
23
  # Instantiate the new exception.
29
24
  #
30
25
  # @example Instantiate the exception.
31
- # Mongo::Error::EmptyBatch.new
26
+ # Mongo::Error::MultiIndexDrop.new
32
27
  #
33
28
  # @since 2.0.0
34
29
  def initialize
35
- super(MESSAGE)
30
+ super("Passing '*' to #drop_one would cause all indexes to be dropped. Please use #drop_all")
36
31
  end
37
32
  end
38
33
  end