Skip to content

RUST-1120 bson's is_human_readable not configurable from mongodb side #530

Open
@alon-z

Description

@alon-z

Hey, we are trying to save a struct with ipnet::Ipv4Net and the serializers are using the is_human_readable serde option to distinguish between different cases.
When inserting the struct, it serializes with is_human_readable false (this issue is referenced in bson's 2.1.0-beta changelog) but when using find commands, the deserializer is set with is_human_readable true by default.
In result, we cant save and use the struct in mongo.

In bson 2.1.0-beta they added options to set the is_human_readable variable.
If there could be a way we can set it so the deserializer will set is_human_readable to false when using find commands, we will be able to solve this issue :)

Example below

use ipnet::Ipv4Net;
use mongodb::error::Result as MongoResult;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Subnets {
    pub private: Ipv4Net,
    pub public: Ipv4Net,
}

impl Subnets {
    pub async fn init(subnets: Vec<Subnets>) -> MongoResult<mongodb::Cursor<Subnets>> {
        let client = mongodb::Client::with_uri_str("mongodb://localhost:27017")
            .await
            .expect("Failed to initialize mongodb client");
        let db = client.database("ipnet");
        let coll = db.collection::<Subnets>("subnets");

        coll.insert_many(subnets, None).await?; // Will insert the address like Array["10","0","0","1","16"]
        coll.find(None, None).await // Try's to find address like "10.0.0.1/16"
    }
}

Metadata

Metadata

Assignees

No one assigned

    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