lib/mongo/error/bulk_write_error.rb in mongo-2.6.4 vs lib/mongo/error/bulk_write_error.rb in mongo-2.7.0.rc0
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright (C) 2014-2018 MongoDB, Inc.
+# Copyright (C) 2014-2019 MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@@ -33,9 +33,25 @@
# reporting results of the operation.
#
# @since 2.0.0
def initialize(result)
@result = result
+ end
+
+ def to_s
+ messages = if errors = result['writeErrors']
+ frag = ': ' + errors[0..10].map do |error|
+ "#{error['errmsg']} (#{error['code']})"
+ end.join(', ')
+ if errors.length > 10
+ frag += '...'
+ else
+ frag
+ end
+ else
+ ''
+ end
+ self.class.name + messages
end
end
end
end