Skip to content

Instantly share code, notes, and snippets.

@JamesKovacs
JamesKovacs / SyncMongoClientConnectionExample.rs
Created March 15, 2023 22:12
MongoDB Rust Sync Connection Example without StableAPI
use mongodb::{bson::doc, options::ClientOptions, sync::Client};
fn main() -> mongodb::error::Result<()> {
// Parse your connection string into an options struct
let client_options =
ClientOptions::parse("<connection string>")?;
// Get a handle to the cluster
let client = Client::with_options(client_options)?;
@JamesKovacs
JamesKovacs / SyncMongoClientConnectionExampleWithStableAPI.rs
Last active March 15, 2023 22:09
MongoDB Rust Sync Connection Example with StableAPI
use mongodb::{bson::doc, options::{ClientOptions, ServerApi, ServerApiVersion}, sync::Client};
fn main() -> mongodb::error::Result<()> {
// Parse your connection string into an options struct
let mut client_options =
ClientOptions::parse("<connection string>")?;
// Set the server_api field of the client_options object to Stable API version 1
let server_api = ServerApi::builder().version(ServerApiVersion::V1).build();
client_options.server_api = Some(server_api);
@JamesKovacs
JamesKovacs / MongoClientConnectionExample.rs
Created March 8, 2023 23:12
MongoDB Rust Connection Example without StableAPI
use mongodb::{bson::doc, options::ClientOptions, Client};
#[tokio::main]
async fn main() -> mongodb::error::Result<()> {
// Parse your connection string into an options struct
let client_options =
ClientOptions::parse("<connection string>")
.await?;
// Get a handle to the cluster
@JamesKovacs
JamesKovacs / MongoClientConnectionExampleWithStableAPI.rs
Last active March 8, 2023 23:19
MongoDB Rust Connection Example with StableAPI
use mongodb::{bson::doc, options::{ClientOptions, ServerApi, ServerApiVersion}, Client};
#[tokio::main]
async fn main() -> mongodb::error::Result<()> {
// Parse your connection string into an options struct
let mut client_options =
ClientOptions::parse("<connection string>")
.await?;
// Set the server_api field of the client_options object to Stable API version 1
@JamesKovacs
JamesKovacs / MongoClientConnectionExampleWithStableAPI.cs
Created March 8, 2023 22:59
MongoDB C# Connection Example with StableAPI
using MongoDB.Driver;
using MongoDB.Bson;
// Replace the placeholders with your credentials
const string connectionUri = "<connection string>";
var settings = MongoClientSettings.FromConnectionString(connectionUri);
// Set the ServerApi field of the settings object to Stable API version 1
settings.ServerApi = new ServerApi(ServerApiVersion.V1);
@JamesKovacs
JamesKovacs / MongoClientConnectionExample.cs
Created March 8, 2023 22:56
MongoDB C# Connection Example without StableAPI
using MongoDB.Driver;
using MongoDB.Bson;
// Replace the placeholders with your credentials
const string connectionUri = "<connection string>";
var settings = MongoClientSettings.FromConnectionString(connectionUri);
// Create a new client and connect to the server
var client = new MongoClient(settings);
import-module .\psake.psm1
invoke-psake @args
remove-module psake