-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scram.cs
38 lines (30 loc) · 1.25 KB
/
Scram.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.Collections.Generic;
using System.IO;
using MongoDB.Bson;
using MongoDB.Driver;
using System;
using System.Threading.Tasks;
// Tested using MongoDB.Driver 2.9.2 and netcoreapp 2.2
namespace WorkingWithMongoDB
{
class Program
{
static void Main(string[] args)
{
MainAsync().Wait();
}
static async Task MainAsync()
{
// note that you can specify the username and password here or use these as placeholders and override with the CreateCredential below
var connectionString = "mongodb+srv://username:[email protected]/test?retryWrites=true&w=majority";
var settings = MongoClientSettings.FromConnectionString(connectionString);
settings.Credential = MongoCredential.CreateCredential("admin", "admin", "admin");
var client = new MongoClient(settings);
// just doing a quick read to verify the usability of this connection
var database = client.GetDatabase("testDB");
var collection = database.GetCollection<BsonDocument>("testCol");
var docCount = collection.CountDocuments("{}");
Console.WriteLine(docCount);
}
}
}