Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-1164

Serde helper "serialize_object_id_as_hex_string" influences the query type for a field

    • Type: Icon: Bug Bug
    • Resolution: Won't Do
    • Priority: Icon: Major - P3 Major - P3
    • No version
    • Affects Version/s: None
    • Component/s: Embedded Shell
    • Labels:
      None
    • Environment:
      Fedora 35, Rust 1.58.0
    • Not Needed

      Problem Statement/Rationale

      If we create a struct which will be used as a collection generic type, and we set the '#[serde(serialize_with = "serialize_object_id_as_hex_string")]' serde helper for the '_id' field (or an other ObjectId field). Then we can not query that field with an ObjectId only with its hex representation.
       

      Steps to Reproduce

      Consider the following struct:

      pub struct User {
        #[serde(serialize_with = "serialize_object_id_as_hex_string")]
        pub _id: ObjectId,
        pub email: String,
        pub password: String,
        pub username: String,
      }

       

      Now, if try to query a collection using this as the generic type, then query will not give any result:

      let id = ObjectId::from_str(&id)let filter = doc!{"_id": ObjectId::from};
      {{ let update = doc!{"$set": {"confirmed": true}};}}

      users_coll.update_one(filter, update, None).await
        .map_err(|_| ErrorInternalServerError(""))?;

      Expected Results

      What do you expect to happen?

      Actual Results

      What do you observe is happening?

      Additional Notes

      Any additional information that may be useful to include.

            Assignee:
            Unassigned Unassigned
            Reporter:
            horvbalint99@gmail.com Bálint Horváth
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: