Closed amber-m-o-r-e closed 4 years ago
Hey @amber-m-o-r-e looks like you are using an old version of Wither with the new version of the mongo driver. You need to use the latest alpha release of wither (0.9.0-alpha.1).
If you still have issues, check out #53
Keep me posted. Happy to help.
@rumanbsl just making sure you saw my response over there: https://github.com/thedodd/wither/issues/53#issuecomment-653182243 :)
@amber-m-o-r-e any update on this front? Things working out for you? If so, do you mind closing this issue? I don't want to close it myself if you still need assistance.
It works well with one warning but I think since we are using alpha build in future it will be resolve, reference code-
use futures::stream::StreamExt;
use serde::{Serialize, Deserialize};
use wither::{prelude::*, Result};
use wither::bson::{doc, oid::ObjectId};
use wither::mongodb::Client;
// Define a model. Simple as deriving a few traits.
#[derive(Debug, Model, Serialize, Deserialize)]
#[model(index(keys=r#"doc!{"email": 1}"#, options=r#"doc!{"unique": true}"#))]
struct User {
/// The ID of the model.
#[serde(rename="_id", skip_serializing_if="Option::is_none")]
pub id: Option<ObjectId>,
/// The user's email address.
pub email: String,
}
#[tokio::main]
async fn main() -> Result<()> {
// Connect & sync indexes.
let db = Client::with_uri_str("mongodb://localhost:27017/").await?.database("mydb");
User::sync(db.clone()).await?;
// Create a user.
let mut me = User{id: None, email: String::from("my.email@example.com")};
me.save(db.clone(), None).await?;
// Update user's email address.
me.update(db.clone(), None, doc!{"$set": doc!{"email": "new.email@example.com"}}, None).await?;
// Fetch all users.
let mut cursor = User::find(db.clone(), None, None).await?;
while let Some(user) = cursor.next().await {
println!("{:?}", user);
}
Ok(())
}
toml-
[dependencies]
futures = "0.3.5"
serde = "1.0.114"
serde_derive = "1.0.114"
wither = { version = "0.9.0-alpha.1", default-features = false, features = ["async-std-runtime"] }
tokio = { version = "0.2.21", features = ["full"] }
Compiled Readme.md code against following toml dependencies and getting buch of errors.
Code
toml dependencies
Errors