-
Notifications
You must be signed in to change notification settings - Fork 178
RUST-1488 BulkWriteFailure does not contain inserted_ids when insert_many fails #748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @decatur! The panic is expected given that you call Regarding the non-violating documents not getting inserted when ordered=false, I'm not able to reproduce this. I've written the following program: use futures::stream::TryStreamExt;
use mongodb::{Client, Collection, bson::Document, bson::doc, options::InsertManyOptions};
#[tokio::main]
async fn main() -> mongodb::error::Result<()>{
let client = Client::with_uri_str("mongodb://localhost:27017,localhost:27018,localhost:27019/?replicaSet=repl0").await?;
let coll: Collection<Document> = client.database("bulk_test").collection("test");
// clear out any existing data
coll.drop(None).await?;
coll.insert_one(
doc! { "_id": 1},
None
).await?;
let mut cursor = coll.find(None, None).await?;
println!("querying collection after insert_one");
while let Some(result) = cursor.try_next().await? {
println!("Found document: {}", result);
}
let insert_opts = InsertManyOptions::builder().ordered(false).build();
let insert_result = coll.insert_many(
[
doc! { "_id": 1},
doc! { "_id": 2},
doc! { "_id": 3}
],
insert_opts
).await;
match insert_result {
Ok(_) => { println!("insert succeeded") },
Err(e) => { println!("insert failed with error: {}", e) },
};
println!("querying collection after insert_many");
let mut cursor = coll.find(None, None).await?;
while let Some(result) = cursor.try_next().await? {
println!("Found document: {}", result);
}
Ok(())
} Which produces the following output:
Given the output it appears that the documents following the violating one, with Can you give me some more information about the data you inserting (what the documents look like, what the unique index looks like)? How are you verifying whether the non-violating documents were inserted after encountering the error? |
There has not been any recent activity on this ticket, so we are marking it as stale. If we do not hear anything further from you, this issue will be automatically closed in one week. |
Hello @kmahar, you are right, the non-violating documents get inserted, and I checked that the sitting document does not get updated! What threw me off though is the
whereas clearly two documents were inserted. |
Considerung both #761 and the fact that (at least with the Node driver) the desired result (getting a list of documents not inserted) can be achieved with
I will close this issue. Note that we did not tested the |
Versions/Environment
Describe the bug
The documentation states:
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:
The panic is
The use case is optimistic locking: Bulk insert those documents which are not yet inserted.
The text was updated successfully, but these errors were encountered: