Skip to content

RUST-1743 Question: GridFS is the rust driver compatible with the java driver? #938

Closed
@jse1t5

Description

@jse1t5

Versions/Environment

  1. What version of Rust are you using? 1.70
  2. What operating system are you using? macOS Ventura 13.4.1
  3. What versions of the driver and its dependencies are you using?
  1. What version of MongoDB are you using? 5.0.12
  2. What is your MongoDB topology standalone

Describe the bug

We're actually trying to read a file from a GridFsBucket in Java which was created in Rust.
Java claims that it cannot cast a Long value into an Integer.

Im not sure why this happens but in my case on the Upload side in Rust the "chunkSize" in "fs.files" and "n" in "fs.chunks" has the type int64.
It seems like the driver is implemented with a u32 ?!

https://github.com/mongodb/mongo-rust-driver/blob/v2.6.1/src/gridfs.rs#L55
https://github.com/mongodb/mongo-rust-driver/blob/v2.6.1/src/gridfs.rs#L34

Currently we use the Java driver version:

<dependency>
      <groupId>org.mongodb</groupId>
      <artifactId>mongodb-driver-sync</artifactId>
      <version>4.6.1</version>
      <scope>compile</scope>
</dependency>

A File upload on the java side stores chunkSize and n as i32.

To Reproduce
Steps to reproduce the behavior:

  1. Create File via GridFsBucket in Rust
  2. Read File via GridFsBucket in Java

For now the following Code fixes my Problem but it would be nice to remove this Workaround:

async fn fix_mongodb_types(db: &DB, oid: &Bson) -> anyhow::Result<()> {
    let mut opts = FindOneOptions::default();
    opts.projection = Some(doc! { "chunkSize": 1});
    let file = db.client().collection::<DocChunkSize>("fs.files").find_one(doc! { "_id": &oid }, Some(opts)).await?.unwrap();
    db.client().collection::<Document>("fs.files").update_one(
        doc! { "_id": oid }, 
        doc! {
        "$set": {
            "chunkSize": Bson::Int32(file.chunk_size as i32)
        }
    }, None).await?;
    let mut opts = FindOptions::default();
    opts.projection = Some(doc! { "_id": 1, "n": 1 });
    let mut chunks = db.client().collection::<DocN>("fs.chunks").find(doc! { "files_id": &oid }, None).await?;
    while let Some(ch) = chunks.next().await {
        if let Ok(ch) = ch {
            db.client().collection::<Document>("fs.chunks").update_one(
                doc! { "_id": &ch.id }, 
                doc! {
                "$set": {
                    "n": Bson::Int32(ch.n as i32)
                }
            }, None).await?;
        }
    }
    Ok(())
}

Metadata

Metadata

Assignees

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