Tuxedo is a library for masking and transferring your MongoDB database collections between instances
This library is currently in production and can regularly experience breaking changes
[dependencies]
tuxedo = { version = "0.1.0" }
use tuxedo::{
Mask, MongoModel, ProcessorConfigBuilder, ReplicationManagerBuilder, ReplicationStrategy, TuxedoResult,
};
#[derive(Clone, Debug, Serialize, Deserialize, MongoModel)]
#[mongo_model(collection = "users")]
pub struct User {
#[serde(rename = "_id")]
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<ObjectId>,
pub first_name: String,
pub last_name: String,
}
impl Mask for User {
fn mask(&mut self) {
self.first_name = Self::fake_first_name();
self.last_name = Self::fake_last_name();
}
}
#[tokio::main]
async fn main() -> TuxedoResult<()> {
let replication_manager = ReplicationManagerBuilder::new()
.source_uri("mongodb://localhost:27017")
.target_uri("mongodb://localhost:27016")
.source_db("source_db_name")
.target_db("target_db_name")
.batch_size(2500 as usize)
.strategy(ReplicationStrategy::Mask)
.add_processor::<User>()
.build()
.await?;
replication_manager.run().await?;
Ok(())
}
Processors are used for collections that need to be masked.
They can be configured individually using a ProcessorConfigBuilder
alongside the add_processor_with_config
function. This is required for things like discriminators/polymorphic models, and can be done by overriding the query
as needed to ensure no duplicate entries are created.
Replicators are used for collections that need to be replicated, but do not need to be masked. They have the benefit of not requiring a struct to replicate the data, but are also significantly slower as they as (de)serialized using a bson::Document, which is much less ideal then a defined struct. It is recommended for larger collections to use a struct and define the Mask
trait with a NOP to avoid the masking portion, but allow for much faster replication speeds.