diff --git a/source/MongoDB/Exceptions/MongoMapReduceException.cs b/source/MongoDB/Exceptions/MongoMapReduceException.cs index db68852f..562ff29a 100644 --- a/source/MongoDB/Exceptions/MongoMapReduceException.cs +++ b/source/MongoDB/Exceptions/MongoMapReduceException.cs @@ -5,7 +5,7 @@ namespace MongoDB /// /// Raised when a map reduce call fails. /// - public class MongoMapReduceException : MongoCommandException + public class MongoMapReduceException : MongoCommandException { /// /// Gets or sets the map reduce result. @@ -14,7 +14,7 @@ public class MongoMapReduceException : MongoCommandException public MapReduceResult MapReduceResult { get; private set; } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The exception. public MongoMapReduceException(MongoCommandException exception) diff --git a/source/MongoDB/IMongoCollection_1.cs b/source/MongoDB/IMongoCollection_1.cs index 77df8f59..1af776bb 100644 --- a/source/MongoDB/IMongoCollection_1.cs +++ b/source/MongoDB/IMongoCollection_1.cs @@ -156,7 +156,7 @@ public interface IMongoCollection /// Entrypoint into executing a map/reduce query against the collection. /// /// - MapReduce MapReduce(); + MapReduce MapReduce(); /// /// Count all items in the collection. diff --git a/source/MongoDB/MapReduce.cs b/source/MongoDB/MapReduce.cs index d9ac3849..c072948b 100644 --- a/source/MongoDB/MapReduce.cs +++ b/source/MongoDB/MapReduce.cs @@ -8,25 +8,29 @@ namespace MongoDB /// /// Provides a Fluent interface to build and execute Map/Reduce calls. /// - public class MapReduce : IDisposable - where T : class + public class MapReduce : IDisposable { private readonly IMongoDatabase _database; + private readonly Type _rootType; private bool _canModify = true; private bool _disposing; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The database. /// The name. - public MapReduce(IMongoDatabase database, string name) + /// Type of the root. + public MapReduce(IMongoDatabase database, string name, Type rootType) { if(database == null) throw new ArgumentNullException("database"); if(name == null) throw new ArgumentNullException("name"); + if(rootType == null) + throw new ArgumentNullException("rootType"); + _rootType = rootType; _database = database; Command = new MapReduceCommand(name); } @@ -87,7 +91,7 @@ public void Dispose() /// A map function must call emit(key,value) at least once, but may be invoked any number of times, /// as may be appropriate. /// - public MapReduce Map(string function) + public MapReduce Map(string function) { return Map(new Code(function)); } @@ -97,7 +101,7 @@ public MapReduce Map(string function) /// A map function must call emit(key,value) at least once, but may be invoked any number of times, /// as may be appropriate. /// - public MapReduce Map(Code function) + public MapReduce Map(Code function) { TryModify(); Command.Map = function; @@ -112,7 +116,7 @@ public MapReduce Map(Code function) /// The MapReduce engine may invoke reduce functions iteratively; thus, these functions /// must be idempotent. If you need to perform an operation only once, use a finalize function. /// - public MapReduce Reduce(string function) + public MapReduce Reduce(string function) { return Reduce(new Code(function)); } @@ -125,7 +129,7 @@ public MapReduce Reduce(string function) /// The MapReduce engine may invoke reduce functions iteratively; thus, these functions /// must be idempotent. If you need to perform an operation only once, use a finalize function. /// - public MapReduce Reduce(Code function) + public MapReduce Reduce(Code function) { TryModify(); Command.Reduce = function; @@ -135,7 +139,7 @@ public MapReduce Reduce(Code function) /// /// Query filter object /// - public MapReduce Query(Document query) + public MapReduce Query(Document query) { TryModify(); Command.Query = query; @@ -145,7 +149,7 @@ public MapReduce Query(Document query) /// /// Sort the query. Useful for optimization /// - public MapReduce Sort(Document sort) + public MapReduce Sort(Document sort) { TryModify(); Command.Sort = sort; @@ -155,7 +159,7 @@ public MapReduce Sort(Document sort) /// /// Number of objects to return from collection /// - public MapReduce Limit(long limit) + public MapReduce Limit(long limit) { TryModify(); Command.Limit = limit; @@ -168,7 +172,7 @@ public MapReduce Limit(long limit) /// /// A temporary collection is still used and then renamed to the target name atomically. /// - public MapReduce Out(String name) + public MapReduce Out(String name) { TryModify(); Command.Out = name; @@ -179,7 +183,7 @@ public MapReduce Out(String name) /// When true the generated collection is not treated as temporary. Specifying out automatically makes /// the collection permanent /// - public MapReduce KeepTemp(bool keep) + public MapReduce KeepTemp(bool keep) { TryModify(); Command.KeepTemp = keep; @@ -189,7 +193,7 @@ public MapReduce KeepTemp(bool keep) /// /// Provides statistics on job execution time. /// - public MapReduce Verbose(bool val) + public MapReduce Verbose(bool val) { TryModify(); Command.Verbose = val; @@ -199,7 +203,7 @@ public MapReduce Verbose(bool val) /// /// Function to apply to all the results when finished. /// - public MapReduce Finalize(Code function) + public MapReduce Finalize(Code function) { TryModify(); Command.Finalize = function; @@ -209,7 +213,7 @@ public MapReduce Finalize(Code function) /// /// Document where fields go into javascript global scope /// - public MapReduce Scope(Document scope) + public MapReduce Scope(Document scope) { TryModify(); Command.Scope = scope; @@ -228,12 +232,12 @@ internal void RetrieveData() try { - Result = new MapReduceResult(_database.SendCommand(typeof(T), Command.Command)); + Result = new MapReduceResult(_database.SendCommand(_rootType, Command.Command)); } catch(MongoCommandException exception) { Result = new MapReduceResult(exception.Error); - throw new MongoMapReduceException(exception); + throw new MongoMapReduceException(exception); } } diff --git a/source/MongoDB/MongoCollection_1.cs b/source/MongoDB/MongoCollection_1.cs index 6a40a725..732d42cf 100644 --- a/source/MongoDB/MongoCollection_1.cs +++ b/source/MongoDB/MongoCollection_1.cs @@ -232,8 +232,8 @@ public T FindOne(string javascriptWhere) /// Entrypoint into executing a map/reduce query against the collection. /// /// A - public MapReduce MapReduce(){ - return new MapReduce(Database, Name); + public MapReduce MapReduce(){ + return new MapReduce(Database, Name, typeof(T)); } /// diff --git a/source/MongoDB/Obsolete/IMongoCollection.cs b/source/MongoDB/Obsolete/IMongoCollection.cs index 16e25235..6c1b78fd 100644 --- a/source/MongoDB/Obsolete/IMongoCollection.cs +++ b/source/MongoDB/Obsolete/IMongoCollection.cs @@ -129,7 +129,7 @@ public interface IMongoCollection /// Maps the reduce. /// /// - MapReduce MapReduce(); + MapReduce MapReduce(); /// /// Counts this instance. diff --git a/source/MongoDB/Obsolete/MongoCollection.cs b/source/MongoDB/Obsolete/MongoCollection.cs index ee8e064a..1ad8f1db 100644 --- a/source/MongoDB/Obsolete/MongoCollection.cs +++ b/source/MongoDB/Obsolete/MongoCollection.cs @@ -180,7 +180,7 @@ public Document FindAndModify (Document document, Document spec, Document sort, /// Maps the reduce. /// /// - public MapReduce MapReduce(){ + public MapReduce MapReduce(){ return _collection.MapReduce(); }