Skip to content
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

RUST-2054 Incorrect default index name when creating an index #1225

Open
biro456 opened this issue Oct 13, 2024 · 2 comments
Open

RUST-2054 Incorrect default index name when creating an index #1225

biro456 opened this issue Oct 13, 2024 · 2 comments
Assignees

Comments

@biro456
Copy link

biro456 commented Oct 13, 2024

Versions/Environment

  1. What version of Rust are you using? rustc 1.81.0 (eeb90cda1 2024-09-04)
  2. What operating system are you using? Ubuntu 22.04.4 LTS on WSL/Windows 10 Pro 22H2
  3. What versions of the driver and its dependencies are you using? [email protected] and [email protected]
  4. What version of MongoDB are you using? MongoDB 8.0.1 Community
  5. What is your MongoDB topology (standalone, replica set, sharded cluster, serverless)? standalone

Describe the bug

When creating indexes with the text, 2d, 2dsphere or hashed types the default index name generated by the driver does not follow the documentation.

Steps to reproduce

  1. Start a local MongoDB server
  2. Run this snippet
use mongodb::bson::{doc, Document};
use mongodb::error::Result;
use mongodb::{Client, IndexModel};

#[tokio::main]
async fn main() -> Result<()> {
  let client = Client::with_uri_str("mongodb://localhost:27017").await?;
  let db = client.database("test");

  db.create_collection("test").await?;

  let col = db.collection::<Document>("test");

  col.create_index(IndexModel::builder().keys(doc! { "field": "2d" }).build()).await?;

  Ok(())
}
  1. Verify the index name with the shell or Compass
Expected result

The index is named field_2d.

Actual result

The index is named field_"2d".

image

The problem boils down to

.map(|(k, v)| format!("{}_{}", k, v))

where the Bson conversion of v to a string is always wrapped by ".
Since this logic is not public I had to reproduce it in my code and that's how I found the bug.

@abr-egn
Copy link
Contributor

abr-egn commented Oct 14, 2024

Thanks for the detailed report! I'm looking into this now.

@abr-egn abr-egn changed the title Incorrect default index name when creating an index RUST-2054 Incorrect default index name when creating an index Oct 14, 2024
@abr-egn
Copy link
Contributor

abr-egn commented Oct 16, 2024

I just merged #1226 which fixes this, and will go out in our next release. Thanks again for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants