Skip to content

Commit

Permalink
chore: replace boilerplate connection code with setup_db module
Browse files Browse the repository at this point in the history
  • Loading branch information
extua committed Jun 20, 2024
1 parent b4e77be commit 6512969
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions json_adder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,8 @@ mod setup_db;
#[tokio::main]

async fn main() -> mongodb::error::Result<()> {
setup_db::get_collection().await;
// Is it possible to wrap up some of this boilerplate connection code?
let uri: &str = "mongodb://ADMIN:PASSWORD@localhost:27017";
let mut client_options = ClientOptions::parse_async(uri).await?;

// Set the server_api field of the client_options object to Stable API version 1
let server_api = ServerApi::builder().version(ServerApiVersion::V1).build();
client_options.server_api = Some(server_api);

// Create a new client and connect to the server
let client: Client = Client::with_options(client_options)?;

// Connect to the database and the snapshot collection document
let database = client.database("communities");
let snapshot_collection = database.collection("hourly_snapshot");

let snapshot_collection = setup_db::get_collection().await;

for file in fs::read_dir("../../api.freifunk.net/data/history/").unwrap() {
// File path for sample json file, change this later
Expand Down

0 comments on commit 6512969

Please sign in to comment.