1313* limitations under the License.
1414*/
1515
16- using System ;
1716using System . Collections . Generic ;
1817using System . Collections . ObjectModel ;
1918using System . Linq ;
20- using System . Text ;
2119using MongoDB . Bson ;
2220using MongoDB . Driver . Support ;
2321
@@ -260,11 +258,13 @@ public static BulkWriteBatchResult Create(
260258 var unprocessedRequests = Enumerable . Empty < WriteRequest > ( ) ;
261259 BsonValue upsertId = null ;
262260 var documentsAffected = 0L ;
263- if ( writeConcernResult != null )
261+
262+ if ( writeConcernResult != null )
264263 {
265- documentsAffected = writeConcernResult . DocumentsAffected ;
266264 upsertId = writeConcernResult . Upserted ;
265+ documentsAffected = writeConcernResult . DocumentsAffected ;
267266 var updateRequest = request as UpdateRequest ;
267+
268268 if ( upsertId == null &&
269269 documentsAffected == 1 &&
270270 updateRequest != null &&
@@ -273,13 +273,12 @@ public static BulkWriteBatchResult Create(
273273 {
274274 // Get the _id field first from the Update document
275275 // and then from the Query document.
276- upsertId = updateRequest . Update . ToBsonDocument ( )
277- . GetValue (
278- "_id" ,
279- updateRequest . Query . ToBsonDocument ( )
280- . GetValue ( "_id" , null ) ) ;
276+ upsertId =
277+ updateRequest . Update . ToBsonDocument ( ) . GetValue ( "_id" , null ) ??
278+ updateRequest . Query . ToBsonDocument ( ) . GetValue ( "_id" , null ) ;
281279 }
282280 }
281+
283282 var upserts = ( upsertId == null ) ? Enumerable . Empty < BulkWriteUpsert > ( ) : new [ ] { new BulkWriteUpsert ( 0 , upsertId ) } ;
284283 var writeErrors = __noWriteErrors ;
285284 WriteConcernError writeConcernError = null ;
0 commit comments