Skip to content

DOCSP-44862 Update aggregation code examples #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions source/includes/fundamentals/code-snippets/aggregation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bson::{ doc, DateTime };
use bson::{ doc, DateTime, Document };
use mongodb::{ Client, Collection };
Copy link
Collaborator Author

@stephmarie17 stephmarie17 Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note for tech reviewer] Are the all updates in this file also ok to backport for <3.0 versions or is there any difference to note?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual call to aggregate is different pre-3.0 because the aggregate method used to accept a second parameter with options, but the removal of from_document would still apply

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, ty!

use serde::{ Deserialize, Serialize };
use futures::stream::TryStreamExt;

#[tokio::main]
async fn main() -> mongodb::error::Result<()> {
Expand Down Expand Up @@ -42,8 +43,7 @@ async fn main() -> mongodb::error::Result<()> {

let mut results = my_coll.aggregate(age_pipeline).await?;
while let Some(result) = results.try_next().await? {
let doc = mongodb::bson::from_document(result)?;
println!("* {:?}", doc);
println!("* {:?}", result);
}
// end-age-agg

Expand All @@ -57,8 +57,7 @@ async fn main() -> mongodb::error::Result<()> {

let mut results = my_coll.aggregate(last_active_pipeline).await?;
while let Some(result) = results.try_next().await? {
let doc = mongodb::bson::from_document(result)?;
println!("* {:?}", doc);
println!("* {:?}", result);
}
// end-lastactive-agg

Expand All @@ -72,8 +71,7 @@ async fn main() -> mongodb::error::Result<()> {

let mut results = my_coll.aggregate(popularity_pipeline).await?;
while let Some(result) = results.try_next().await? {
let doc = mongodb::bson::from_document(result)?;
println!("* {:?}", doc);
println!("* {:?}", result);
}
// end-popular-agg

Expand Down
Loading