コード例 #1
0
 public virtual void MapReduce <TEntity>(MapReduceOptionsProxy <TEntity, TEntity> options) where TEntity : CollectionEntityBase, new()
 {
     this.MapReduce <TEntity, TEntity>(options);
 }
コード例 #2
0
        public virtual IEnumerable <TResult> MapReduce <TEntity, TResult>(MapReduceOptionsProxy <TEntity, TResult> options) where TEntity : CollectionEntityBase, new()
        {
            if (string.IsNullOrEmpty(options.Map))
            {
                throw new Exception("map is must");
            }
            if (string.IsNullOrEmpty(options.Reduce))
            {
                throw new Exception("reduce is must");
            }
            var o = new MapReduceOptions <TEntity, TResult>();

            if (options.OutputEnum.Equals(MapReduceOutputOptionsEnum.Inline))
            {
                o.OutputOptions = MapReduceOutputOptions.Inline;
            }
            else
            {
                if (string.IsNullOrEmpty(options.DatabaseName) || string.IsNullOrEmpty(options.CollectionName))
                {
                    throw new Exception("DatabaseName and CollectionName is must");
                }
                if (options.OutputEnum.Equals(MapReduceOutputOptionsEnum.Merge))
                {
                    o.OutputOptions = MapReduceOutputOptions.Reduce(options.CollectionName, options.DatabaseName);
                }
                else if (options.OutputEnum.Equals(MapReduceOutputOptionsEnum.Reduce))
                {
                    o.OutputOptions = MapReduceOutputOptions.Reduce(options.CollectionName, options.DatabaseName);
                }
                else if (options.OutputEnum.Equals(MapReduceOutputOptionsEnum.Replace))
                {
                    o.OutputOptions = MapReduceOutputOptions.Replace(options.CollectionName, options.DatabaseName);
                }
            }
            o.BypassDocumentValidation = options.BypassDocumentValidation;
            if (!string.IsNullOrEmpty(options.Filter))
            {
                o.Filter = options.Filter;
            }
            if (!string.IsNullOrEmpty(options.Finalize))
            {
                o.Finalize = options.Finalize;
            }
            o.JavaScriptMode = options.JavaScriptMode;
            o.Limit          = options.Limit;
            o.MaxTime        = options.MaxTime;
            if (!string.IsNullOrEmpty(options.Sort))
            {
                o.Sort = options.Sort;
            }
            o.Verbose = options.Verbose;
            var r = this.CurrentCollection <TEntity>().MapReduce <TResult>(new MongoDB.Bson.BsonJavaScript(options.Map), new MongoDB.Bson.BsonJavaScript(options.Reduce), o);

            if (options.OutputEnum.Equals(MapReduceOutputOptionsEnum.Inline))
            {
                return(r.Current);
            }
            else
            {
                return(null);
            }
        }