Updated use of credential builder to make code more efficient and removed unrelated JSON file
This commit is contained in:
		
							
								
								
									
										12
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/main.rs
									
									
									
									
									
								
							| @@ -11,19 +11,21 @@ async fn main() { | |||||||
|  |  | ||||||
|     // Manually set an option. |     // Manually set an option. | ||||||
|     client_options.app_name = Some("My App".to_string()); |     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()); |     let credential_builder = Credential::builder() | ||||||
|     client_options.credential.as_mut().unwrap().password = Some(std::env::var("mongo_password").unwrap()); |                             .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. |     // Get a handle to the deployment. | ||||||
|     let client = Client::with_options(client_options).unwrap(); |     let client = Client::with_options(client_options).unwrap(); | ||||||
|  |  | ||||||
|     let db = client.database("test"); |     let db = client.database("test"); | ||||||
|      |  | ||||||
|     match db.create_collection("test", None).await { |     match db.create_collection("test", None).await { | ||||||
|         Err(_) => panic!("ERROR: incorrect usage"), |         Err(_) => panic!("ERROR: incorrect usage"), | ||||||
|         _ => {} |         _ => {} | ||||||
|     } |     } | ||||||
|  |      | ||||||
|     let collection = db.collection::<Packet>("test"); |     let collection = db.collection::<Packet>("test"); | ||||||
|  |  | ||||||
|     loop { |     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" |  | ||||||
| } |  | ||||||
		Reference in New Issue
	
	Block a user