Closed Bryson14 closed 7 months ago
example of data currently in mongodb
{
"_id": {
"$oid": "65fdf259bc497a1b87a5c9ce"
},
"sso": "123456789",
"content_privacy_consent": null,
"content_privacy_consent_date": null,
"create_time": {
"$date": "2024-02-11T02:29:05.302Z"
},
"last_access_time": {
"$date": "2024-03-09T22:21:26.890Z"
},
"user_id": "018d95ff-2e96-7169-9d08-175b96d4e7e3"
}
Hi @Bryson14, thanks for this detailed report! We do indeed have a bug in our deserialization logic for UUIDs that are not in binary format. I made a PR to fix this (#468), so we'll put out a patch release once that's approved and merged. Once the fix is in, your UUID deserialization from strings when using the bson::Uuid
type should work without needing to enable any feature flags.
I was unable to reproduce the compilation errors you're encountering. Are you seeing those errors with the chrono-0_4
, uuid-1
, and serde_with-3
feature flags enabled?
I think the serde_with
error was fixed by https://github.com/mongodb/bson-rust/commit/81a98950899f96b138699e008e4d1703ed0f8fb5.
I'll give the feature flags a try again. For the bson::uuid, it was too much time dealing with it that I just went with treating the data from the database as strings (which they are strings from the migration). I would have to change the rust code and database UUIDs to deal with this right now and I don't see any good benefit from using bson::uuid at the moment. Perhaps performance?
I don't see any good benefit from using bson::uuid at the moment
It depends upon your use case. If you're just reading your data via the driver then it likely doesn't matter much which type you're using, but bson::Uuid
provides utilities for constructing values that could be useful if you're inserting new data.
I'm going to close this out since the fix in #468 has been released, but feel free to create another issue if you have any further feedback or questions!
Versions/Environment
cargo pkgid mongodb
&cargo pkgid bson
) 2.9.0 & 2.8.2db.version()
) 7.2.0Describe the bug
A clear and concise description of what the bug is.
I am migrating data from another database which includes UUIDs stored as strings. I understand that bson::uuid stores data as binary base-64 data with a subtype flag = 4, however my current database is using strings and the rust code interacting with it is expected deserialization to and from strings.
My current struct definition:
When I run
find()
to get items from this collection I get,I tried to remedy this by changed
uuid::Uuid
in the struct definition tobson::Uuid
but got a similar error:Trying to use the serde_with-3 flag didn't help and I actually got compiler errors. This was after adding the feature flag with
cargo add bson -F serde_with-3
. The documentation didn't say that I had to add other dependancies to get this to work.what to do:
So I'm thinking there are two fixes to this. Either I fix this issue in code and get the serialization and deserialization to play well with uuid::Uuid, or I migrate all the fields that contain string uuid in the db to Mongo's UUID format. In that case, I'd appreciate any tools to do that, but might just have to bite the bullet and write a small python scipt to do that.
To Reproduce
Cargo.toml