@@ -26,6 +26,25 @@ class BulkInsert
2626 class Result < Operation ::Result
2727 include BulkMergable
2828
29+ # Get the ids of the inserted documents.
30+ #
31+ # @since 2.0.0
32+ attr_reader :inserted_ids
33+
34+ # Initialize a new result.
35+ #
36+ # @example Instantiate the result.
37+ # Result.new(replies, inserted_ids)
38+ #
39+ # @param [ Protocol::Reply ] replies The wire protocol replies.
40+ # @params [ Array<Object> ] ids The ids of the inserted documents.
41+ #
42+ # @since 2.0.0
43+ def initialize ( replies , ids )
44+ @replies = replies . is_a? ( Protocol ::Reply ) ? [ replies ] : replies
45+ @inserted_ids = ids
46+ end
47+
2948 # Gets the number of documents inserted.
3049 #
3150 # @example Get the number of documents inserted.
@@ -37,6 +56,18 @@ class Result < Operation::Result
3756 def n_inserted
3857 written_count
3958 end
59+
60+ # Gets the id of the document inserted.
61+ #
62+ # @example Get id of the document inserted.
63+ # result.inserted_id
64+ #
65+ # @return [ Object ] The id of the document inserted.
66+ #
67+ # @since 2.0.0
68+ def inserted_id
69+ inserted_ids . first
70+ end
4071 end
4172
4273 # Defines custom behaviour of results when inserting.
@@ -46,6 +77,25 @@ def n_inserted
4677 class LegacyResult < Operation ::Result
4778 include LegacyBulkMergable
4879
80+ # Get the ids of the inserted documents.
81+ #
82+ # @since 2.0.0
83+ attr_reader :inserted_ids
84+
85+ # Initialize a new result.
86+ #
87+ # @example Instantiate the result.
88+ # Result.new(replies, inserted_ids)
89+ #
90+ # @param [ Protocol::Reply ] replies The wire protocol replies.
91+ # @params [ Array<Object> ] ids The ids of the inserted documents.
92+ #
93+ # @since 2.0.0
94+ def initialize ( replies , ids )
95+ @replies = replies . is_a? ( Protocol ::Reply ) ? [ replies ] : replies
96+ @inserted_ids = ids
97+ end
98+
4999 # Gets the number of documents inserted.
50100 #
51101 # @example Get the number of documents inserted.
@@ -61,6 +111,18 @@ def n_inserted
61111 n
62112 end
63113 end
114+
115+ # Gets the id of the document inserted.
116+ #
117+ # @example Get id of the document inserted.
118+ # result.inserted_id
119+ #
120+ # @return [ Object ] The id of the document inserted.
121+ #
122+ # @since 2.0.0
123+ def inserted_id
124+ inserted_ids . first
125+ end
64126 end
65127 end
66128 end
0 commit comments