@@ -71,6 +71,45 @@ class BulkWriteResult {
71
71
this . result = bulkResult ;
72
72
}
73
73
74
+ /** Number of documents inserted. */
75
+ get insertedCount ( ) {
76
+ return typeof this . result . nInserted !== 'number' ? 0 : this . result . nInserted ;
77
+ }
78
+ /** Number of documents matched for update. */
79
+ get matchedCount ( ) {
80
+ return typeof this . result . nMatched !== 'number' ? 0 : this . result . nMatched ;
81
+ }
82
+ /** Number of documents modified. */
83
+ get modifiedCount ( ) {
84
+ return typeof this . result . nModified !== 'number' ? 0 : this . result . nModified ;
85
+ }
86
+ /** Number of documents deleted. */
87
+ get deletedCount ( ) {
88
+ return typeof this . result . nRemoved !== 'number' ? 0 : this . result . nRemoved ;
89
+ }
90
+ /** Number of documents upserted. */
91
+ get upsertedCount ( ) {
92
+ return ! this . result . upserted ? 0 : this . result . upserted . length ;
93
+ }
94
+
95
+ /** Upserted document generated Id's, hash key is the index of the originating operation */
96
+ get upsertedIds ( ) {
97
+ const upserted = { } ;
98
+ for ( const doc of ! this . result . upserted ? [ ] : this . result . upserted ) {
99
+ upserted [ doc . index ] = doc . _id ;
100
+ }
101
+ return upserted ;
102
+ }
103
+
104
+ /** Inserted document generated Id's, hash key is the index of the originating operation */
105
+ get insertedIds ( ) {
106
+ const inserted = { } ;
107
+ for ( const doc of ! this . result . insertedIds ? [ ] : this . result . insertedIds ) {
108
+ inserted [ doc . index ] = doc . _id ;
109
+ }
110
+ return inserted ;
111
+ }
112
+
74
113
/**
75
114
* Evaluates to true if the bulk operation correctly executes
76
115
* @type {boolean }
@@ -572,6 +611,35 @@ class BulkWriteError extends MongoError {
572
611
this . name = 'BulkWriteError' ;
573
612
this . result = result ;
574
613
}
614
+
615
+ /** Number of documents inserted. */
616
+ get insertedCount ( ) {
617
+ return this . result . insertedCount ;
618
+ }
619
+ /** Number of documents matched for update. */
620
+ get matchedCount ( ) {
621
+ return this . result . matchedCount ;
622
+ }
623
+ /** Number of documents modified. */
624
+ get modifiedCount ( ) {
625
+ return this . result . modifiedCount ;
626
+ }
627
+ /** Number of documents deleted. */
628
+ get deletedCount ( ) {
629
+ return this . result . deletedCount ;
630
+ }
631
+ /** Number of documents upserted. */
632
+ get upsertedCount ( ) {
633
+ return this . result . upsertedCount ;
634
+ }
635
+ /** Inserted document generated Id's, hash key is the index of the originating operation */
636
+ get insertedIds ( ) {
637
+ return this . result . insertedIds ;
638
+ }
639
+ /** Upserted document generated Id's, hash key is the index of the originating operation */
640
+ get upsertedIds ( ) {
641
+ return this . result . upsertedIds ;
642
+ }
575
643
}
576
644
577
645
/**
0 commit comments