Ejemplo n.º 1
0
        public AutoMapIndexDefinition(string collection, IndexField[] fields)
            : base(IndexNameFinder.FindMapIndexName(new[] { collection }, fields), new[] { collection }, IndexLockMode.Unlock, fields)
        {
            if (string.IsNullOrEmpty(collection))
            {
                throw new ArgumentNullException(nameof(collection));
            }

            if (fields.Length == 0)
            {
                throw new ArgumentException("You must specify at least one field.", nameof(fields));
            }
        }
        public AutoMapReduceIndexDefinition(string[] collections, IndexField[] mapFields, IndexField[] groupByFields)
            : base(IndexNameFinder.FindMapReduceIndexName(collections, mapFields, groupByFields), collections, IndexLockMode.Unlock, mapFields)
        {
            foreach (var field in mapFields)
            {
                if (field.Storage != FieldStorage.Yes)
                {
                    throw new ArgumentException($"Map-reduce field has to be stored. Field name: {field.Name}");
                }
            }

            foreach (var field in groupByFields)
            {
                if (field.Storage != FieldStorage.Yes)
                {
                    throw new ArgumentException($"GroupBy field has to be stored. Field name: {field.Name}");
                }
            }

            GroupByFields = groupByFields.ToDictionary(x => x.Name, x => x, StringComparer.OrdinalIgnoreCase);;
        }