1 / 1
Jun 2024

Hi guys,
I’m writing an indexer to sync data from the blockchain and store it in MongoDB
This is my struct

#[derive(Serialize, Deserialize, Debug)] #[serde(rename_all = "camelCase")] pub struct Arena { #[serde(rename = "_id", skip_serializing_if = "Option::is_none")] pub id: Option<ObjectId>, pub arena_id: ObjectID, pub token: String, pub pool_type: PoolType, #[serde(with = "bson::serde_helpers::chrono_datetime_as_bson_datetime")] pub created_at: DateTime<Utc>, #[serde(with = "bson::serde_helpers::chrono_datetime_as_bson_datetime")] pub updated_at: DateTime<Utc>, }

Note that the ObjectId is from MongoDB
while the ObjectID is from sui-types, which is what I want to focus on in this question

if setting the arena_id as ObjectID and persisting into MongoDB, it will be stored as an array like in the image below:

How can I keep the arena_id as ObjectID, which is stored as a string type when persisting in MongoDB?

I know I have to do something with the serde library, but both ObjectID and serde::Serialize trait are outside of my crate, so I can not do impl Serialize for ObjectID
Thanks