Closed
Description
Versions/Environment
- What version of Rust are you using?
rustc 1.84.0-nightly
- What operating system are you using?
macOS - What versions of the driver and its dependencies are you using? (Run
cargo pkgid mongodb
&cargo pkgid bson
)
registry+https://github.com/rust-lang/crates.io-index#[email protected]
registry+https://github.com/rust-lang/crates.io-index#[email protected]
- What version of MongoDB are you using? (Check with the MongoDB shell using
db.version()
)
8.0.3
- What is your MongoDB topology (standalone, replica set, sharded cluster, serverless)?
replica set
Describe the bug
Error when calling bulk_write
function.
BE SPECIFIC:
- What is the expected behavior and what is actually happening?
bulk_write
fn is supposed to work fine like other DB operations (insert_one, update_one, delete_one...). Also, defined namespace as well. - Do you have any particular output that demonstrates this problem?
Error: Kind: Command failed: Error code 8000 (AtlasError): missing nsInfo, labels: {}
- Do you have any ideas on why this may be happening that could give us a
clue in the right direction?
I searched in the internet, may be due to the cluster being shared which I don't believe. - Did this issue arise out of nowhere, or after an update (of the driver,
server, and/or Rust)?
I am usingbulk_write
for the 1st time in any of the rust crate version. So, not sure about its output in older version. - Are there multiple ways of triggering this bug (perhaps more than one
function produce a crash)? - If you know how to reproduce this bug, please include a code snippet here:
View code
#[tokio::main]
async fn main() -> eyre::Result<()> {
dotenvy::from_path("./.env").expect("Failed to load the env file");
let mongodb_uri = std::env::var("MONGODB_URI").expect("Invalid MONGODB_URI");
let client = mongodb::Client::with_uri_str(mongodb_uri)
.await
.expect("Failed to connect to MongoDB");
let db = client.database("hello");
let collection: Collection<Document> = db.collection("hello3");
// M-1: multiple requests to DB for delete, insert, update.
// m_1(&collection).await?;
m_2(&db, &collection).await?;
Ok(())
}
async fn m_2(db: &Database, collection: &Collection<Document>) -> eyre::Result<()> {
let sample = doc! {
"balance": Decimal128::from_str("1002343243235352.034325345233243241")?,
"pending_amt": Decimal128::from_str("200.03456")?
};
let num = Decimal128::from_str("100.434")?;
let pipeline = vec![
doc! {
"$set": {
"balance": {
"$add": [
"$balance",
bson!(num)
]
}
}
},
doc! {
"$set": {
"balance": {
"$subtract": [
"$balance",
bson!(num)
]
}
}
},
doc! {
"$set": {
"balance": {
"$subtract": [
"$balance",
"$pending_amt"
]
}
}
},
];
let namespace = collection.namespace();
let namespace = Namespace { db: "hello".to_string(), coll: "hello3".to_string() };
println!("{:?}", namespace);
let delete_model = WriteModel::DeleteOne(
DeleteOneModel::builder()
.filter(doc! {})
.collation(None)
.hint(None)
.namespace(namespace.clone())
.build(),
);
let insert_model = WriteModel::InsertOne(
InsertOneModel::builder().document(sample).namespace(namespace.clone()).build(),
);
let update_model = WriteModel::UpdateOne(
UpdateOneModel::builder()
.filter(doc! {})
.update(pipeline)
.array_filters(None)
.collation(None)
.hint(None)
.namespace(namespace)
.build(),
);
let models = vec![delete_model, insert_model, update_model];
// let result = db.client().bulk_write(models).await?;
let result = collection.client().bulk_write(models).await?;
println!("{:?}", result);
Ok(())
}
To Reproduce
Steps to reproduce the behavior:
- Used the code above.
- Run via
cargo r
- Bug occurs.
Namespace { db: "hello", coll: "hello3" }
Error: Kind: Command failed: Error code 8000 (AtlasError): missing nsInfo, labels: {}
Location:
libs/databases/mongo/demo/examples/hello3.rs:150:18