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

Positional $ operator gets the index wrong #953

Open
moy2010 opened this issue Sep 7, 2023 · 1 comment
Open

Positional $ operator gets the index wrong #953

moy2010 opened this issue Sep 7, 2023 · 1 comment
Assignees

Comments

@moy2010
Copy link
Contributor

moy2010 commented Sep 7, 2023

Versions/Environment

  1. What version of Rust are you using? 1.70.0
  2. What operating system are you using? Ubuntu 22.04
  3. What versions of the driver and its dependencies are you using? mongodb 2.5.0 and bson 2.6.1
  4. What version of MongoDB are you using? 6.0.6
  5. What is your MongoDB topology (standalone, replica set, sharded cluster, serverless)? Standalone

Describe the bug

Using the $ positional operator in an update_one operation gets the index for the update wrong.

To Reproduce

Example of the query that shows the error:

my_collection
  .update_one(
    doc! { "my_field.type": "UpdateMe" },
    doc! { "$set": { "my_field.$.type": "Updated" } },
    None,
  )
.await?;

Let's assume that I'm running the integration tests and the my_field array only has one document. In this case, I'm expecting the $ operator to become the index 0, but unfortunately this is not the case and the example above will actually insert a new document into the array at index 1.

I validated that this is a bug by manually replacing the operator with the expected index, and then the integration tests pass:

my_collection
  .update_one(
    doc! { "my_field.type": "UpdateMe" },
    doc! { "$set": { "my_field.0.type": "Updated" } },
    None,
  )
.await?;
@github-actions github-actions bot added the triage label Sep 7, 2023
@moy2010 moy2010 changed the title Positional $ operator get the index wrong Positional $ operator gets the index wrong Sep 7, 2023
@abr-egn
Copy link
Contributor

abr-egn commented Sep 12, 2023

Hi!

At first glance, this doesn't look like behavior specific to the Rust driver. Can you check with the driver for a different language and see if this behavior is present there as well?

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

3 participants