Skip to content

Commit d44a0bd

Browse files
committed
distinct improvements and remove unnecessary structs (#80)
(cherry picked from commit 753da0a)
1 parent 997a323 commit d44a0bd

File tree

6 files changed

+16
-44
lines changed

6 files changed

+16
-44
lines changed

source/includes/usage-examples/code-snippets/count-async.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
use std::env;
2-
32
use mongodb::{ bson::doc, Client, Collection };
4-
use serde::{ Deserialize, Serialize };
5-
6-
#[derive(Serialize, Deserialize, Debug)]
7-
struct Restaurant {
8-
name: String,
9-
}
3+
use bson::Document;
104

115
#[tokio::main]
126
async fn main() -> mongodb::error::Result<()> {
137
let uri = "<connection string>";
148

159
let client = Client::with_uri_str(uri).await?;
16-
let my_coll: Collection<Restaurant> = client
10+
let my_coll: Collection<Document> = client
1711
.database("sample_restaurants")
1812
.collection("restaurants");
1913

source/includes/usage-examples/code-snippets/count-sync.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
use std::env;
2-
32
use mongodb::{ bson::doc, sync::{ Client, Collection } };
4-
use serde::{ Deserialize, Serialize };
5-
6-
#[derive(Serialize, Deserialize, Debug)]
7-
struct Restaurant {
8-
name: String,
9-
}
3+
use bson::Document;
104

115
fn main() -> mongodb::error::Result<()> {
126
let uri = "<connection string>";
137

148
let client = Client::with_uri_str(uri)?;
15-
let my_coll: Collection<Restaurant> = client
9+
let my_coll: Collection<Document> = client
1610
.database("sample_restaurants")
1711
.collection("restaurants");
1812

source/includes/usage-examples/code-snippets/distinct-async.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
use std::env;
2-
32
use mongodb::{ bson::doc, Client, Collection };
4-
use serde::{ Deserialize, Serialize };
5-
6-
#[derive(Serialize, Deserialize, Debug)]
7-
struct Restaurant {
8-
borough: String,
9-
cuisine: String,
10-
}
3+
use bson::Document;
114

125
#[tokio::main]
136
async fn main() -> mongodb::error::Result<()> {
147
let uri = "<connection string>";
158

169
let client = Client::with_uri_str(uri).await?;
17-
let my_coll: Collection<Restaurant> = client
10+
let my_coll: Collection<Document> = client
1811
.database("sample_restaurants")
1912
.collection("restaurants");
2013

source/includes/usage-examples/code-snippets/distinct-sync.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
use std::env;
2-
32
use mongodb::{ bson::doc, sync::{ Client, Collection } };
4-
use serde::{ Deserialize, Serialize };
5-
6-
#[derive(Serialize, Deserialize, Debug)]
7-
struct Restaurant {
8-
borough: String,
9-
cuisine: String,
10-
}
3+
use bson::Document;
114

125
fn main() -> mongodb::error::Result<()> {
136
let uri = "<connection string>";
147

158
let client = Client::with_uri_str(uri)?;
16-
let my_coll: Collection<Restaurant> = client
9+
let my_coll: Collection<Document> = client
1710
.database("sample_restaurants")
1811
.collection("restaurants");
1912

source/usage-examples/count.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ Example
2727
-------
2828

2929
This example counts documents in the ``restaurants`` collection of the
30-
``sample_restaurants`` database. The example uses a ``Restaurant``
31-
struct that has a ``name`` field to model the documents in the
32-
collection.
30+
``sample_restaurants`` database.
3331

3432
The following code first uses the ``estimated_document_count()`` method
3533
to count the total number of documents in the collection. Then, the

source/usage-examples/distinct.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
List Distinct Field Values
55
==========================
66

7-
You can list the distinct field values of documents by calling the
8-
`distinct() <{+api+}/struct.Collection.html#method.distinct>`__ method
9-
on a ``Collection`` instance.
7+
You can list the distinct values of a document field in a collection by
8+
calling the `distinct() <{+api+}/struct.Collection.html#method.distinct>`__
9+
method on a ``Collection`` instance. For example, if documents in a
10+
collection contain the ``date`` field, you can use the ``distinct()``
11+
method to find all the possible values for that field in the collection.
1012

1113
Pass a field name as a parameter to the ``distinct()`` method to return
1214
the distinct values for that field. You can also pass a query filter as
@@ -20,10 +22,8 @@ type, a vector of `Bson <{+bson-api+}/enum.Bson.html>`__ values.
2022
Example
2123
-------
2224

23-
This example finds distinct field values across the
24-
``restaurants`` collection of the ``sample_restaurants`` database. The
25-
example uses a ``Restaurant`` struct that has ``cuisine`` and
26-
``borough`` fields to model documents in the collection.
25+
This example finds distinct values for a field in the
26+
``restaurants`` collection of the ``sample_restaurants`` database.
2727

2828
The following code finds distinct values of the ``borough`` field in
2929
the subset of documents in which the value of the ``cuisine`` field

0 commit comments

Comments
 (0)