use std::any::Any;
use mongodb::{bson::doc,bson::Document, options::ClientOptions,error::Result, Client};
use tokio::task;
use serde::{Deserialize, Serialize};
use futures::stream::TryStreamExt;
#[derive(Clone, Debug, Deserialize, Serialize)]
struct Item {
index: u32,
}
#[tokio::main]
async fn main() -> mongodb::error::Result<()> {
let mut client_options = ClientOptions::parse("mongodb://localhost:27017").await?;
// Manually set an option
client_options.app_name = Some("Rust Demo".to_string());
// Get a handle to the cluster
let client = Client::with_options(client_options)?;
// Ping the server to see if you can connect to the cluster
client
.database("user")
.run_command(doc! {"ping": 1}, None)
.await?;
let db = client.database("Items");
let db_ref = db.clone();
let handle = task::spawn(async move {
let coll = db_ref.collection::<Item>("in_stock");
let filter = doc! {"index": 1000};
let mut findresult = coll.find(filter, None).await.unwrap();
while let Some(r) = findresult.try_next().await.unwrap(){
println!("{:?}", r);
}
});
handle.await;
println!("successfully.");
Ok(())
}
I want to know my _id from my collection info.
But, No _id filed in rust, nodejs easy.
let me know about how to show _id fileld?