use bson::{oid::ObjectId, Bson};
use notmongo::*;
use serde_json;
use std::{
convert::{TryFrom, TryInto},
path::Path,
str::FromStr,
};
const OID_STR_1: &str = "63262de863ff65c8327b1de6";
const OID_STR_2: &str = "63262df763ff65c8327b1de7";
fn id_bson(id: &str) -> Bson {
bson::Bson::try_from(serde_json::json!({
"_id": {
"$oid": id
}
}))
.unwrap()
}
fn id_doc(id: &str) -> bson::Document {
let mut result = bson::Document::new();
result.insert("_id", ObjectId::parse_str(id).unwrap());
result
}
fn catch_main() -> Result<(), String> {
let mut db = Database::new_empty();
let collection = db.collection_mut("col1");
collection.insert_one(id_doc(OID_STR_1))?;
collection.insert_one(id_doc(OID_STR_2))?;
let query = FindQuery::parse_bson(id_bson(OID_STR_1)).unwrap();
let projection = Projection::new_keep_all();
let sorting = Sort::new_unsorted();
let res = collection.find(&query, &projection, 0, 0, &sorting);
for subres in res {
println!("{:?}", subres);
}
Ok(())
}
fn main() {
match catch_main() {
Ok(_) => {}
Err(e) => {
println!("ERROR: {}", e);
}
}
}