public static void BuildTestData()
        {
            var p1 = new Person()
            {
                Age  = 31,
                Name = "Bill"
            };
            var p2 = new Person()
            {
                Age  = 32,
                Name = "Ted"
            };
            var p3 = new Person()
            {
                Age  = 42,
                Name = "Ralph"
            };
            var p4 = new Person()
            {
                Age  = 20,
                Name = "Zoe"
            };

            var mongo = new TestMongoContext();

            mongo.PeopleCollection.RemoveAll();
            mongo.Save(p1);
            mongo.Save(p2);
            mongo.Save(p3);
            mongo.Save(p4);

            p1.FriendIds.Add(p2.Id);
            p1.FriendIds.Add(p3.Id);
            p2.FriendIds.Add(p1.Id);

            mongo.Save(p1);
            mongo.Save(p2);
        }
        public static void BuildTestData()
        {
            var p1 = new Person()
            {
                Age = 31,
                Name = "Bill"
            };
            var p2 = new Person()
            {
                Age = 32,
                Name = "Ted"
            };
            var p3 = new Person()
            {
                Age = 42,
                Name = "Ralph"
            };
            var p4 = new Person()
            {
                Age = 20,
                Name = "Zoe"
            };

            var mongo = new TestMongoContext();
            mongo.PeopleCollection.RemoveAll();
            mongo.Save(p1);
            mongo.Save(p2);
            mongo.Save(p3);
            mongo.Save(p4);

            p1.FriendIds.Add(p2.Id);
            p1.FriendIds.Add(p3.Id);
            p2.FriendIds.Add(p1.Id);

            mongo.Save(p1);
            mongo.Save(p2);
        }
        private static void ExplainQuery()
        {
            Console.WriteLine("=== Explaining queries ===========================");
            TestMongoContext.DropIndexes();
            Console.WriteLine("Without an index:");
            Console.WriteLine();
            Console.WriteLine("Enter to continue");
            Console.ReadKey(true);

            var mongo = new TestMongoContext();
            var query =
                from p in mongo.People
                where p.Age > 20 && p.Name.Length >= 2
                orderby p.Age descending
                select p;

            QueryPlan plan = query.ExplainTyped();
            PrettyPrint(plan);
            Console.WriteLine();
            Console.WriteLine("Using an index? " + (plan.CursorType == CursorType.BtreeCursor));
            Console.WriteLine();

            Console.WriteLine("Enter to continue");
            Console.ReadKey(true);

            TestMongoContext.AddIndexes();
            Console.WriteLine("With an index");
            plan = query.ExplainTyped();
            PrettyPrint(plan);
            Console.WriteLine();
            Console.WriteLine("Using an index? " + (plan.CursorType == CursorType.BtreeCursor));
            Console.WriteLine();

            Console.WriteLine("Enter to continue");
            Console.ReadKey(true);
        }
 public static void DropIndexes()
 {
     var mongo = new TestMongoContext();
     mongo.PeopleCollection.DropAllIndexes();
 }
 public static void AddIndexes()
 {
     var mongo = new TestMongoContext();
     mongo.PeopleCollection.CreateIndex(IndexKeys<Person>.Ascending(p => p.Age));
 }
        private static void ToStringAQuery()
        {
            Console.WriteLine("=== Query.ToMongoQueryText ===========================");

            var mongo = new TestMongoContext();
            var query =
                from p in mongo.People
                where p.Age > 20 && p.Name.Length >= 2
                orderby p.Age descending
                select p;

            Console.WriteLine(query.ToMongoQueryText());
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Enter to continue");
            Console.ReadKey(true);
            Console.WriteLine();
        }
        public static void DropIndexes()
        {
            var mongo = new TestMongoContext();

            mongo.PeopleCollection.DropAllIndexes();
        }
        public static void AddIndexes()
        {
            var mongo = new TestMongoContext();

            mongo.PeopleCollection.CreateIndex(IndexKeys <Person> .Ascending(p => p.Age));
        }