Skip to content

RUST-1488 BulkWriteFailure does not contain inserted_ids when insert_many fails #748

Closed
@decatur

Description

@decatur

Versions/Environment

  1. What version of Rust are you using? cargo 1.60.0
  2. What operating system are you using? MS Windows 10
  3. What versions of the driver and its dependencies are you using? mongodb:2.3.0 & bson:2.4.0
  4. What version of MongoDB are you using? AtlasDB 5.0.12
  5. What is your MongoDB topology (standalone, replica set, sharded cluster, serverless)? M5 (General) Replica Set - 3 nodes

Describe the bug

The documentation states:

ordered:
If true, when an insert fails, return without performing the remaining writes. If false, when a write fails, continue with the remaining writes, if any.

So when inserting documents, with some violating an index, I expect that the insert does not panic but inserts the non-violating documents.
The actual behaviour is: The driver panics, and no document is inserted:

let options = mongodb::options::InsertManyOptions::builder().ordered(false).build();
let res = col.insert_many(document, options).await.unwrap();

The panic is

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: 
Error { kind: BulkWrite(BulkWriteFailure { write_errors: 
  Some([BulkWriteError {
   index: 0, code: 11000, code_name: None, message: "E11000 duplicate key error collection: col_name index: 
   index_name dup key: { field_name: \"X1\" }", details: None }]), write_concern_error: None, inserted_ids: {} }
 ), labels: {}, wire_version: None, source: None }'

The use case is optimistic locking: Bulk insert those documents which are not yet inserted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    tracked-in-jiraTicket filed in Mongo's Jira system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions