Skip to content

Period in document key caused deserialization error #1215

@tqwewe

Description

@tqwewe

Versions/Environment

  1. What version of Rust are you using? 1.80.1
  2. What operating system are you using? OSX
  3. What versions of the driver and its dependencies are you using? [email protected] [email protected]
  4. What version of MongoDB are you using? 8.0
  5. 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:

  1. Insert a MongoDB document with a key that contains a period, such as { "field.name": "value" }.
  2. Use the Rust MongoDB driver to deserialize the document into a struct or Document.
  3. Observe the deserialized output, where the key field.name is split into a nested object: { "field": { "name": "value" } }.
  4. The bug occurs because the deserialization treats the period as a nesting delimiter rather than part of the key.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions