Updated use of credential builder to make code more efficient and removed unrelated JSON file
This commit is contained in:
parent
ce6e443c41
commit
40098478b9
14
src/main.rs
14
src/main.rs
@ -11,19 +11,21 @@ async fn main() {
|
||||
|
||||
// Manually set an option.
|
||||
client_options.app_name = Some("My App".to_string());
|
||||
client_options.credential = Some(Credential::default());
|
||||
client_options.credential.as_mut().unwrap().username = Some(std::env::var("mongo_username").unwrap());
|
||||
client_options.credential.as_mut().unwrap().password = Some(std::env::var("mongo_password").unwrap());
|
||||
|
||||
let credential_builder = Credential::builder()
|
||||
.username(Some(std::env::var("mongo_username").unwrap()))
|
||||
.password(Some(std::env::var("mongo_password").unwrap()));
|
||||
|
||||
client_options.credential = Some(credential_builder.build());
|
||||
|
||||
// Get a handle to the deployment.
|
||||
let client = Client::with_options(client_options).unwrap();
|
||||
|
||||
let db = client.database("test");
|
||||
|
||||
match db.create_collection("test", None).await {
|
||||
Err(_) => panic!("ERROR: incorrect usage"),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
let collection = db.collection::<Packet>("test");
|
||||
|
||||
loop {
|
||||
|
@ -1,19 +0,0 @@
|
||||
{
|
||||
"id": 1,
|
||||
"first_name": "Tom",
|
||||
"last_name": "Cruise",
|
||||
"photo": "https://jsonformatter.org/img/tom-cruise.jpg"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"first_name": "Maria",
|
||||
"last_name": "Sharapova",
|
||||
"photo": "https://jsonformatter.org/img/Maria-Sharapova.jpg
|
||||
"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"first_name": "Robert",
|
||||
"last_name": "Downey Jr",
|
||||
"photo": "https://jsonformatter.org/img/Robert-Downey-Jr.jpg"
|
||||
}
|
Loading…
Reference in New Issue
Block a user