Skip to content

Deserialization implementation for Document doesn't handle documents with extjson keys #419

Open
@PenguinToast

Description

@PenguinToast

Describe the bug

See reproduction below:

    let test_doc = doc! {
        "acutalTimestamp": bson::Timestamp {increment: 0, time: 12345},
        "operationTime": {"$timestamp": "7248047827882870681"},
    };
    let mut bson_bytes = Vec::<u8>::new();
    bson::Document::to_writer(&test_doc, &mut bson_bytes)?;
    let deserialized = bson::from_slice::<bson::Document>(&bson_bytes)?;

This errors with:

Error: invalid type: string "7248047827882870681", expected struct TimestampBody

test_doc is a valid BSON document, however the deserializer doesn't make any distinction between a $timestamp from an actual Timestamp vs. just a document with a $timestamp key. This causes issues with custom Deserialize implementations for data structures, where I can't figure out how to differentiate between a real Timestamp and a Document.

BE SPECIFIC:

  • What is the expected behavior and what is actually happening?
    • This should not error, but it does.

Metadata

Metadata

Assignees

Labels

tracked-in-jiraTicket filed in Mongo's Jira system

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions