-
Type: Task
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
I have been trying to use the MongoDB Rust driver using Tide having given up on Rocket. However, I try and follow examples online and run into a common error:
thread 'main' panicked at 'there is no timer running, must be called from the context of Tokio runtime'
I get this issue regardless of whether I use wither or if I use the mongodb driver. For context, this is the code I have:
#[derive(Clone, Debug)] pub struct State { client: Arc<Client> }#[async_std::main] async fn main() -> Result<(), std::io::Error> { // Configuring DB connection let mut client_options = match ClientOptions::parse("mongodb://localhost:27017").await { Ok(c) => c, Err(e) => panic!("Client Options Failed: {}", e) }; client_options.app_name = Some("App".to_string()); let client = match Client::with_options(client_options) { Ok(c) => c, Err(e) => panic!("Client Creation Failed: {}", e) }; let coll = &client.database("db1").collection("users"); let doc = coll.find_one(None, None).await.unwrap(); println!("{:?}", doc); let engine = State { client: Arc::new(client) }; let mut app = tide::with_state(engine); tide::log::start(); app.at("/").get(|_| async { Ok("Hello, world!") }); app.listen("0.0.0.0:3001").await?; Ok(()) }
It's pretty basic, but it fails everytime and I get a panic. Am I doing anything wrong? The collection has data in it so that will not be the issue (I think).