Closed
Description
Versions/Environment
- What version of Rust are you using?
cargo 1.68.2 (6feb7c9cf 2023-03-26)
- What operating system are you using?
Linux 6.4.3-arch1-2 x86_64 GNU/Linux
- What versions of the driver and its dependencies are you using? (Run
cargo pkgid mongodb
&cargo pkgid bson
)https://github.com/rust-lang/crates.io-index#mongodb@2.6.0 https://github.com/rust-lang/crates.io-index#bson@2.6.1
- What version of MongoDB are you using? (Check with the MongoDB shell using
db.version()
)6.0
- What is your MongoDB topology (standalone, replica set, sharded cluster, serverless)?
replica set
Describe the bug
For types that use different a serializer for human-readable serialization, we face the following issue:
When inserted, values are serialized by the non-human readable serializer on account of using bson::to_vec
under the hood.
However, if we try to replace such values all replace
methods in Collection use internally bson::to_document
that uses the human-readable serializer.
This implies that if we attempt to find such a value that has been replaced and deserialize, we will either get a deserialization error, or incorrect data.
To Reproduce
Steps to reproduce the behavior:
- Define a type that implements
serde_with::SerializeAs
using different serializers for human-readable (e.g.String
) and non-readable (e.g.Bytes
). - Then insert a value of this type into a collection. Store it as
original
- After doing that, replace that value with a clone of itself using any of the Collection methods that replace values (e.g.
replace_one
). - Get the replaced value
replaced
from the database and verify that!assert_eq!(original, replaced)
.
Metadata
Metadata
Assignees
Labels
No labels