MongoDB.DriverUnitTests.MongoCollectionTests.TestAggregate C# (CSharp) Метод

TestAggregate() приватный Метод

private TestAggregate ( ) : void
Результат void
        public void TestAggregate()
        {
            if (_server.BuildInfo.Version >= new Version(2, 1, 0))
            {
                _collection.RemoveAll();
                _collection.DropAllIndexes();
                _collection.Insert(new BsonDocument("x", 1));
                _collection.Insert(new BsonDocument("x", 2));
                _collection.Insert(new BsonDocument("x", 3));
                _collection.Insert(new BsonDocument("x", 3));

                var commandResult = _collection.Aggregate(
                    new BsonDocument("$group", new BsonDocument { { "_id", "$x" }, { "count", new BsonDocument("$sum", 1) } })
                );
                var dictionary = new Dictionary<int, int>();
                foreach (var result in commandResult.ResultDocuments)
                {
                    var x = result["_id"].AsInt32;
                    var count = result["count"].AsInt32;
                    dictionary[x] = count;
                }
                Assert.AreEqual(3, dictionary.Count);
                Assert.AreEqual(1, dictionary[1]);
                Assert.AreEqual(1, dictionary[2]);
                Assert.AreEqual(2, dictionary[3]);
            }
        }