Advertisement
Guest User

MongoDB authentication with C#

a guest
Sep 15th, 2015
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using MongoDB.Bson;
  4. using MongoDB.Driver;
  5.  
  6. namespace mdbtest
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             var watch = new Stopwatch();
  13.             try
  14.             {
  15.                 var client = new MongoClient("mongodb://admin:password@localhost/admin");
  16.                 var db = client.GetDatabase("admin");
  17.                 watch.Start();
  18.                 var result = db.ListCollectionsAsync().Result.ToBsonDocument();
  19.                 Console.WriteLine(result.ToString());
  20.             }
  21.             catch (Exception e)
  22.             {
  23.                 Console.WriteLine(e.InnerException.Message.Substring(0, 79));
  24.             }
  25.             Console.WriteLine("done in {0} ms!", watch.ElapsedMilliseconds);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement