thedodd / wither

An ODM for MongoDB built on the official MongoDB Rust driver.
https://docs.rs/wither
Other
324 stars 40 forks source link

`find_one` always return None #65

Closed losintikfos closed 3 years ago

losintikfos commented 3 years ago

I have this model

use wither::prelude::*;

#[derive(Debug, Clone, Model, PartialEq, Deserialize, Serialize, TypedBuilder)]
#[model(collection_name = "accounts")]
#[model(index(
   keys = r#"doc!{"email": 1}"#,
   options = r#"doc!{"name": "unique-email", "unique": true, "background": true}"#
))]
pub struct Account {
  #[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
  pub(crate) id: Option<ObjectId>,
  pub(crate) email: Option<String>,
  pub(crate) created: Option<String>,
  pub(crate) updated: Option<String>,
}

I have noticed below call always return None although the value exists. Does anyone knows why this is happening?

let filter = Some(bson::doc! { 
  "email": String::from("my.email@example.com") 
});
let select_option = Account::find_one(&db, filter, None).await.map_err(|err| {
    anyhow!("DB Error: :?}", err)
})?

println!("Verify: {:?}", select_option); // <-- Prints None
losintikfos commented 3 years ago

This was totally a bug in my code nothing to do with wither apologies.

thedodd commented 3 years ago

@losintikfos copy that. Sounds good :)