Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,28 @@ use mongodb::{
Client,
Collection
};
use serde::{ Deserialize, Serialize };

#[derive(Debug, Serialize, Deserialize)]
struct Address {
street: String,
city: String,
}

#[derive(Serialize, Deserialize, Debug)]
struct Restaurant {
name: String,
borough: String,
address: Address,
}

#[tokio::main]
async fn main() -> mongodb::error::Result<()> {
let uri = "<connection string>";
let client = Client::with_uri_str(uri).await?;

let my_coll: Collection<Document> = client
// Replace <T> with the <Document> or <Restaurant> type parameter
let my_coll: Collection<T> = client
.database("sample_restaurants")
.collection("restaurants");

Expand Down
17 changes: 16 additions & 1 deletion source/includes/usage-examples/code-snippets/delete-many-sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@ use mongodb::{
bson::{ Document, doc },
sync::{ Client, Collection }
};
use serde::{ Deserialize, Serialize };

#[derive(Debug, Serialize, Deserialize)]
struct Address {
street: String,
city: String,
}

#[derive(Serialize, Deserialize, Debug)]
struct Restaurant {
name: String,
borough: String,
address: Address,
}

fn main() -> mongodb::error::Result<()> {
let uri = "<connection string>";
let client = Client::with_uri_str(uri)?;

let my_coll: Collection<Document> = client
// Replace <T> with the <Document> or <Restaurant> type parameter
let my_coll: Collection<T> = client
.database("sample_restaurants")
.collection("restaurants");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ use mongodb::{
Client,
Collection
};
use serde::{ Deserialize, Serialize };

#[derive(Serialize, Deserialize, Debug)]
struct Restaurant {
name: String,
borough: String,
}

#[tokio::main]
async fn main() -> mongodb::error::Result<()> {
let uri = "<connection string>";
let client = Client::with_uri_str(uri).await?;

let my_coll: Collection<Document> = client
// Replace <T> with the <Document> or <Restaurant> type parameter
let my_coll: Collection<T> = client
.database("sample_restaurants")
.collection("restaurants");

Expand Down
10 changes: 9 additions & 1 deletion source/includes/usage-examples/code-snippets/delete-one-sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ use mongodb::{
bson::{ Document, doc },
sync::{ Client, Collection }
};
use serde::{ Deserialize, Serialize };

#[derive(Serialize, Deserialize, Debug)]
struct Restaurant {
name: String,
borough: String,
}

fn main() -> mongodb::error::Result<()> {
let uri = "<connection string>";
let client = Client::with_uri_str(uri)?;

let my_coll: Collection<Document> = client
// Replace <T> with the <Document> or <Restaurant> type parameter
let my_coll: Collection<T> = client
.database("sample_restaurants")
.collection("restaurants");

Expand Down
17 changes: 13 additions & 4 deletions source/usage-examples/deleteMany.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,19 @@ Example
-------

This example deletes all documents that match a query filter from the ``restaurants``
collection in the ``sample_restaurants`` database.

This example passes a query filter as a parameter to the ``delete_many()`` method.
The filter matches documents in which the value of the ``borough`` field is ``"Manhattan"``
collection in the ``sample_restaurants`` database. The ``delete_many()`` method deletes
documents in which the value of the ``borough`` field is ``"Manhattan"``
and the value of the ``address.street`` field is ``"Broadway"``.

You can access the documents in the ``restaurants`` collection as instances
of the ``Document`` type or a custom data type. To specify which data type
represents the collection's data, replace the ``<T>`` type parameter on the
highlighted line with one of the following values:

- ``<Document>``: Accesses collection documents as BSON documents
- ``<Restaurant>``: Accesses collection documents as instances of the ``Restaurant``
struct, defined at the top of the code

Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to
see the corresponding code for each runtime:

Expand All @@ -55,6 +62,7 @@ see the corresponding code for each runtime:

.. input:: /includes/usage-examples/code-snippets/delete-many-async.rs
:language: rust
:emphasize-lines: 27
:dedent:

.. output::
Expand All @@ -72,6 +80,7 @@ see the corresponding code for each runtime:

.. input:: /includes/usage-examples/code-snippets/delete-many-sync.rs
:language: rust
:emphasize-lines: 25
:dedent:

.. output::
Expand Down
17 changes: 13 additions & 4 deletions source/usage-examples/deleteOne.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ Example
-------

This example deletes a document that matches a query filter from the ``restaurants``
collection in the ``sample_restaurants`` database.
collection in the ``sample_restaurants`` database. The ``delete_one()`` method deletes the
first document in which the value of the ``name`` field is ``"Haagen-Dazs"`` and the
``borough`` field is ``"Brooklyn"``.

This example uses a query filter that matches documents in which the value of the
``name`` field is ``"Haagen-Dazs"`` and the ``borough`` field is ``"Brooklyn"``. MongoDB
deletes the first document that matches the query filter.
You can access the documents in the ``restaurants`` collection as instances
of the ``Document`` type or a custom data type. To specify which data type
represents the collection's data, replace the ``<T>`` type parameter on the
highlighted line with one of the following values:

- ``<Document>``: Accesses collection documents as BSON documents
- ``<Restaurant>``: Accesses collection documents as instances of the ``Restaurant``
struct, defined at the top of the code

Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to
see the corresponding code for each runtime:
Expand All @@ -50,6 +57,7 @@ see the corresponding code for each runtime:

.. input:: /includes/usage-examples/code-snippets/delete-one-async.rs
:language: rust
:emphasize-lines: 20
:dedent:

.. output::
Expand All @@ -66,6 +74,7 @@ see the corresponding code for each runtime:

.. input:: /includes/usage-examples/code-snippets/delete-one-sync.rs
:language: rust
:emphasize-lines: 18
:dedent:

.. output::
Expand Down
Loading