Пример #1
0
        /// <summary>
        /// List all indexes inside a collection
        /// </summary>
        public IEnumerable<BsonDocument> GetIndexes(string colName, bool stats = false)
        {
            var col = this.GetCollectionPage(colName, false);

            if (col == null) yield break;

            foreach (var index in col.GetIndexes(true))
            {
                var doc = new BsonDocument()
                    .Add("slot", index.Slot)
                    .Add("field", index.Field)
                    .Add("options", new BsonDocument()
                        .Add("unique", index.Options.Unique)
                        .Add("ignoreCase", index.Options.IgnoreCase)
                        .Add("removeAccents", index.Options.RemoveAccents)
                        .Add("trimWhitespace", index.Options.TrimWhitespace)
                        .Add("emptyStringToNull", index.Options.EmptyStringToNull)
                    );

                if (stats)
                {
                    _cache.CheckPoint();

                    var pages = _indexer.FindAll(index, Query.Ascending).GroupBy(x => x.Page.PageID).Count();

                    // this command can be consume too many memory!! has no CheckPoint on loop
                    var keySize = pages == 0 ? 0 : _indexer.FindAll(index, Query.Ascending).Average(x => x.KeyLength);

                    doc.Add("stats", new BsonDocument()
                        .Add("pages", pages)
                        .Add("allocated", BasePage.GetSizeOfPages(pages))
                        .Add("keyAverageSize", (int)keySize)
                    );
                }

                yield return doc;
            }
        }