-
Notifications
You must be signed in to change notification settings - Fork 183
Description
Versions/Environment
- What version of Rust are you using? 1.80.1
- What operating system are you using? OSX
- What versions of the driver and its dependencies are you using?
[email protected]
[email protected]
- What version of MongoDB are you using? 8.0
- What is your MongoDB topology? standalone replicaset
Describe the bug
When deserializing a MongoDB document with a key that contains a period (.
), the MongoDB Rust driver separates the period into a nested object during deserialization rather than keeping it as part of the key.
Expected behavior:
Keys with a period (.
) should remain part of the key string during deserialization, just as they are in MongoDB. This is evident since using Compass shows my records correctly with the key containing a .
period.
Actual behavior:
The period (.
) is treated as a nested field, and the key is split into a parent and child object.
Output demonstrating the issue:
For example, a MongoDB document with the key "field.name": "value"
deserializes into { "field": { "name": "value" } }
instead of { "field.name": "value" }
.
Possible reason:
The driver might be misinterpreting periods in keys and treating them as delimiters for nested objects rather than part of the key string. This behavior could be a parsing or deserialization issue specific to the BSON format in Rust.
Impact:
Any keys in MongoDB documents that contain periods (.
) will be incorrectly deserialized into nested objects, potentially causing unexpected behavior in applications.
To Reproduce
Steps to reproduce the behavior:
- Insert a MongoDB document with a key that contains a period, such as
{ "field.name": "value" }
. - Use the Rust MongoDB driver to deserialize the document into a struct or
Document
. - Observe the deserialized output, where the key
field.name
is split into a nested object:{ "field": { "name": "value" } }
. - The bug occurs because the deserialization treats the period as a nesting delimiter rather than part of the key.