Skip to content

ObjectId error #1224

Closed
Closed
@JonathanWoollett-Light

Description

@JonathanWoollett-Light

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? Windows
  3. What versions of the driver and its dependencies are you using? (Run
    cargo pkgid mongodb & cargo pkgid bson)
  4. What version of MongoDB are you using? (Check with the MongoDB shell using db.version()): mongodb-win32-x86_64-windows-7.0.14/bin/mongod.exe
  5. What is your MongoDB topology (standalone, replica set, sharded cluster, serverless)? Standalone

Describe the bug

Within my application I have

    info!("user_id:\n\t{user_id}\n\t{user_id:?}");
    let find_doc = doc! { "_id": user_id };
    info!("find_doc: {find_doc:?}");
    let all_users = users.find(doc!{}).await.unwrap().collect::<Vec<_>>().await;
    info!("all_users: {all_users:?}");
    let user = users
        .find_one(find_doc)
        .await
        .map_err(PickError::QueryUser)?
        .ok_or(PickError::FindUser)?;

upon reaching and executing this in a test I get the error:

500 Internal Server Error, Failed to query user: Kind: invalid value: string "ObjectId(\"670996bba2c4b6ec183babff\")", expected 24-character, big-endian hex string, labels: {}

The notable section here being that it reports the ObjectId as 670996bba2c4b6ec183babff rather than 670996baa2c4b6ec183babfe.

The logs are:

2024-10-11T21:20:59.870511Z  INFO server::pick: user_id:
        670996baa2c4b6ec183babfe
        ObjectId("670996baa2c4b6ec183babfe")
2024-10-11T21:20:59.870662Z  INFO server::pick: find_doc: Document({"_id": ObjectId("670996baa2c4b6ec183babfe")})
2024-10-11T21:20:59.871112Z  INFO server::pick: all_users: [Err(Error { kind: BsonDeserialization(DeserializationError { message: "invalid value: string \"ObjectId(\\\"670996bba2c4b6ec183babff\\\")\", expected 24-character, big-endian hex string" }), labels: {}, wire_version: None, source: None })]

Checking the database with Mongdb Compass I can see:

{
  "_id": {
    "$oid": "670996baa2c4b6ec183babfe"
  },
  ...
}

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions