> This page location: /docs.md > /docs/drivers.md > /docs/languages/rust.md > /docs/drivers/rust/current.md

> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# Quick Reference Syntax Examples

On this page, you can see examples that use the Rust driver to perform several common MongoDB tasks. Each row of the following table describes the task, shows the driver syntax to execute the task, and includes links to the related reference and API documentation.

The Rust driver offers an asynchronous runtime for executing async applications. Additionally, the driver supports a blocking synchronous runtime. For each MongoDB task listed in the following table, you can see examples that use both the asynchronous and synchronous APIs.

**Tip:**

To learn more about asynchronous and synchronous runtimes, see the [Asynchronous and Synchronous APIs](https://www.mongodb.com/docs/drivers/rust/current/runtimes.md#std-label-rust-runtimes) guide.

| Command | Syntax |
| --- | --- |
| **Find a Document**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/struct.Collection.html#method.find_one)[Find Documents](https://www.mongodb.com/docs/drivers/rust/current/crud/query/retrieve.md#std-label-rust-retrieve-guide) | *Async Runtime* `let result = collection.find_one(doc! { "title": "Peter Pan" }).await?;` *Sync Runtime* `let result = collection.find_one(doc! { "title": "Peter Pan" }).run()?;` |
| **Find Multiple Documents**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/struct.Collection.html#method.find)[Find Documents](https://www.mongodb.com/docs/drivers/rust/current/crud/query/retrieve.md#std-label-rust-retrieve-guide) | *Async Runtime* `let filter = doc! { "year": 1925 };
let mut cursor = collection.find(filter).await?;` *Sync Runtime* `let filter = doc! { "year": 1925 };
let mut cursor = collection.find(filter).run()?;` |
| **Insert a Document**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/struct.Collection.html#method.insert_one)[Insert Documents Guide](https://www.mongodb.com/docs/drivers/rust/current/crud/insert.md#std-label-rust-insert-guide) | *Async Runtime* `let doc = doc! {
    "title": "Mistress America", "type": "movie"
};

let result = collection.insert_one(doc).await?;` *Sync Runtime* `let doc = doc! {
    "title": "Mistress America", "type": "movie"
};

let result = collection.insert_one(doc).run()?;` |
| **Insert Multiple Documents**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/struct.Collection.html#method.insert_many)[Insert Documents Guide](https://www.mongodb.com/docs/drivers/rust/current/crud/insert.md#std-label-rust-insert-guide) | *Async Runtime* `let docs = vec![
    doc! { "title": "Friends With Money", "runtime": 88 },
    doc! { "title": "Please Give", "runtime": 90 },
    doc! { "title": "You Hurt My Feelings", "runtime": 93 },
];

let result = collection.insert_many(docs).await?;` *Sync Runtime* `let docs = vec![
    doc! { "title": "Friends With Money", "runtime": 88 },
    doc! { "title": "Please Give", "runtime": 90 },
    doc! { "title": "You Hurt My Feelings", "runtime": 93 },
];

let result = collection.insert_many(docs).run()?;` |
| **Update a Document**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/struct.Collection.html#method.update_one)[Update Documents Guide](https://www.mongodb.com/docs/drivers/rust/current/crud/update.md#std-label-rust-crud-update) | *Async Runtime* `let filter = doc! { "title": "Burn After Reading"};
let update = doc! {
        "$set": doc!{ "num_mflix_comments": 1 }
};

let result = collection.update_one(filter, update).await?;` *Sync Runtime* `let filter = doc! { "title": "Burn After Reading"};
let update = doc! {
        "$set": doc!{ "num_mflix_comments": 1 }
};

let result = collection.update_one(filter, update).run()?;` |
| **Update Multiple Documents**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/struct.Collection.html#method.update_many)[Update Documents Guide](https://www.mongodb.com/docs/drivers/rust/current/crud/update.md#std-label-rust-crud-update) | *Async Runtime* `let filter = doc! { "rated": "PASSED"};
let update = doc! {
        "$set": doc!{ "rated": "Not Rated" }
};

let result = collection.update_many(filter, update).await?;` *Sync Runtime* `let filter = doc! { "rated": "PASSED"};
let update = doc! {
        "$set": doc!{ "rated": "Not Rated" }
};

let result = collection.update_many(filter, update).run()?;` |
| **Replace a Document**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/struct.Collection.html#method.replace_one)[Replace Documents Guide](https://www.mongodb.com/docs/drivers/rust/current/crud/update/replace.md#std-label-rust-change-guide) | *Async Runtime* `let filter = doc! { "title": "è Nous la Libertè" };
let replacement = doc! {
    "title": "À nous la liberté",
    "type": "movie",
    "directors": vec! [ "René Clair" ]
};

let result = collection.replace_one(filter, replacement).await?;` *Sync Runtime* `let filter = doc! { "title": "è Nous la Libertè" };
let replacement = doc! {
    "title": "À nous la liberté",
    "type": "movie",
    "directors": vec! [ "René Clair" ]
};

let result = collection.replace_one(filter, replacement).run()?;` |
| **Delete a Document**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/struct.Collection.html#method.delete_one)[Delete Documents Guide](https://www.mongodb.com/docs/drivers/rust/current/crud/delete.md#std-label-rust-delete-guide) | *Async Runtime* `let filter = doc! { "title": "Search and Destroy" };
let result = collection.delete_one(filter).await?;` *Sync Runtime* `let filter = doc! { "title": "Search and Destroy" };
let result = collection.delete_one(filter).run()?;` |
| **Delete Multiple Documents**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/struct.Collection.html#method.delete_many)[Delete Documents Guide](https://www.mongodb.com/docs/drivers/rust/current/crud/delete.md#std-label-rust-delete-guide) | *Async Runtime* `let filter = doc! {
    "year": doc! { "$lt": 1920 }
};

let result = collection.delete_many(filter).await?;` *Sync Runtime* `let filter = doc! {
    "year": doc! { "$lt": 1920 }
};

let result = collection.delete_many(filter).run()?;` |
| **Access Data from a Cursor Iteratively**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/struct.Cursor.html)[Access Data from a Cursor Guide](https://www.mongodb.com/docs/drivers/rust/current/crud/query/cursor.md#std-label-rust-cursor-guide) | *Async Runtime* `let mut cursor = collection
    .find(doc! { "$and": vec!
    [
        doc! { "metacritic": doc! { "$gt": 90 } },
        doc! { "directors": vec! [ "Martin Scorsese" ] }
    ] })
    .await?;

while let Some(result) = cursor.try_next().await? {
    println!("{}", result);
}` *Sync Runtime* `let cursor = collection
    .find(doc! { "$and": vec!
    [
        doc! { "metacritic": doc! { "$gt": 90 } },
        doc! { "directors": vec! [ "Martin Scorsese" ] }
    ] })
    .run()?;

for result in cursor {
    println!("{}", result?);
}` |
| **Access Data from a Cursor as an Array**[API Documentation](https://docs.rs/futures/latest/futures/stream/trait.TryStreamExt.html#method.try_collect)[Access Data from a Cursor Guide](https://www.mongodb.com/docs/drivers/rust/current/crud/query/cursor.md#std-label-rust-cursor-guide) | *Async Runtime* `let cursor = collection.find(doc! { "title": "Secrets & Lies" }).await?;

let results: Vec<Document> = cursor.try_collect().await?;` *Sync Runtime* `let cursor = collection.find(doc! { "title": "Secrets & Lies" }).run()?;

let results: Vec<Result<Document>> = cursor.collect();` |
| **Count Documents**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/struct.Collection.html#method.count_documents)[Count Documents Guide](https://www.mongodb.com/docs/drivers/rust/current/crud/query/count.md#std-label-rust-count-documents) | *Async Runtime* `let filter = doc! {
    "languages": vec! [ "Mandarin" ]
};

let result = collection.count_documents(filter).await?;` *Sync Runtime* `let filter = doc! {
    "languages": vec! [ "Mandarin" ]
};

let result = collection.count_documents(filter).run()?;` |
| **List Distinct Values of a Field**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/struct.Collection.html#method.distinct)[Distinct Field Values Guide](https://www.mongodb.com/docs/drivers/rust/current/crud/query/distinct.md#std-label-rust-distinct) | *Async Runtime* `let field_name = "title";
let filter = doc! {
    "directors": vec! [ "Sean Baker" ]
};

let results = collection.distinct(field_name, filter).await?;` *Sync Runtime* `let field_name = "title";
let filter = doc! {
    "directors": vec! [ "Sean Baker" ]
};

let results = collection.distinct(field_name, filter).run()?;` |
| **Limit the Number of Documents Retrieved**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/options/struct.FindOptions.html#structfield.limit)[Specify Documents Guide](https://www.mongodb.com/docs/drivers/rust/current/crud/query/specify-documents.md#std-label-rust-specify-documents) | *Async Runtime* `let filter = doc! { "awards.wins": 25};
let mut cursor = collection.find(filter).limit(5).await?;` *Sync Runtime* `let filter = doc! { "awards.wins": 25};
let mut cursor = collection.find(filter).limit(5).run()?;` |
| **Skip Retrieved Documents**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/options/struct.FindOptions.html#structfield.skip)[Specify Documents Guide](https://www.mongodb.com/docs/drivers/rust/current/crud/query/specify-documents.md#std-label-rust-specify-documents) | *Async Runtime* `let filter = doc! { "runtime": 100 };
let mut cursor = collection.find(filter).skip(1).await?;` *Sync Runtime* `let filter = doc! { "runtime": 100 };
let mut cursor = collection.find(filter).skip(1).run()?;` |
| **Sort the Documents When Retrieving Them**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/options/struct.FindOptions.html#structfield.sort)[Specify Documents Guide](https://www.mongodb.com/docs/drivers/rust/current/crud/query/specify-documents.md#std-label-rust-specify-documents) | *Async Runtime* `let filter = doc! {
    "directors": vec! [ "Nicole Holofcener" ]
};

let mut cursor = collection
    .find(filter)
    .sort(doc! { "imdb.rating": 1 })
    .await?;` *Sync Runtime* `let filter = doc! {
    "directors": vec! [ "Nicole Holofcener" ]
};

let mut cursor = collection
    .find(filter)
    .sort(doc! { "imdb.rating": 1 })
    .run()?;` |
| **Project Document Fields When Retrieving Them**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/options/struct.FindOptions.html#structfield.projection)[Specify Fields Guide](https://www.mongodb.com/docs/drivers/rust/current/crud/query/specify-fields.md#std-label-rust-specify-fields) | *Async Runtime* `let filter = doc! { "year": 2015 };
let mut cursor = collection
    .find(filter)
    .projection(doc! { "title": 1, "metacritic": 1, "_id": 0 })
    .await?;` *Sync Runtime* `let filter = doc! { "year": 2015 };
let mut cursor = collection
    .find(filter)
    .projection(doc! { "title": 1, "metacritic": 1, "_id": 0 })
    .run()?;` |
| **Create an Index**[API Documentation](https://docs.rs/mongodb/3.10.1/mongodb/struct.Collection.html#method.create_index)[Create Indexes Guide](https://www.mongodb.com/docs/drivers/rust/current/indexes.md#std-label-rust-indexes) | *Async Runtime* `let index: IndexModel = IndexModel::builder().keys(doc! { "title": 1 }).build();

let result = collection.create_index(index).await?;` *Sync Runtime* `let index: IndexModel = IndexModel::builder().keys(doc! { "title": 1 }).build();

let result = collection.create_index(index).run()?;` |
