Blazingly fast and simple data generation & seeding for MongoDB
Use the package manager cargo to install planter. Add the following to your Cargo.toml
[dependencies]
planter = {git = "https://github.com/valencian-digital/planter", branch = "main"}# from online repo```
fn user_generator(_history: &planter::GeneratedData) -> bson::Document {
return doc! {
"_id": bson::Bson::ObjectId(bson::oid::ObjectId::new()),
"name": "Jane Doe"
};
}
...
let documents_per_collection = 1000;
let collections: Vec<(String, planter::EntityGenerator)> = vec![
(String::from("users"), user_generator),
];
planter::seed_data(
collections,
planter::Configurations::new(documents_per_collection, planter::SeedMode::Disk),
);
Then to import that data into your running MongoDB database, execute the following command:
mongorestore --db=test data/
Look at the mongorestore documentation in order to see all of options
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.