def map_reduce(self, map, reduce, full_response=False, **kwargs): """Perform a map/reduce operation on this collection. If `full_response` is ``False`` (default) returns a :class:`~pymongo.collection.Collection` instance containing the results of the operation. Otherwise, returns the full response from the server to the `map reduce command`_. :Parameters: - `map`: map function (as a JavaScript string) - `reduce`: reduce function (as a JavaScript string) - `full_response` (optional): if ``True``, return full response to this command - otherwise just return the result collection - `**kwargs` (optional): additional arguments to the `map reduce command`_ may be passed as keyword arguments to this helper method, e.g.:: >>> db.test.map_reduce(map, reduce, limit=2) .. note:: Requires server version **>= 1.1.1** .. seealso:: :doc:`/examples/map_reduce` .. versionadded:: 1.2 .. _map reduce command: http://www.mongodb.org/display/DOCS/MapReduce """ command = SON([("mapreduce", self.__name), ("map", map), ("reduce", reduce)]) command.update(**kwargs) response = self.__database.command(command) if full_response: return response return self.__database[response["result"]]
def map_reduce(self, map, reduce, full_response=False, **kwargs): """Perform a map/reduce operation on this collection. If `full_response` is ``False`` (default) returns a :class:`~pymongo.collection.Collection` instance containing the results of the operation. Otherwise, returns the full response from the server to the `map reduce command`_. :Parameters: - `map`: map function (as a JavaScript string) - `reduce`: reduce function (as a JavaScript string) - `full_response` (optional): if ``True``, return full response to this command - otherwise just return the result collection - `**kwargs` (optional): additional arguments to the `map reduce command`_ may be passed as keyword arguments to this helper method, e.g.:: >>> db.test.map_reduce(map, reduce, limit=2) .. note:: Requires server version **>= 1.1.1** .. seealso:: :doc:`/examples/map_reduce` .. versionadded:: 1.1.2+ .. _map reduce command: http://www.mongodb.org/display/DOCS/MapReduce """ command = SON([("mapreduce", self.__collection_name), ("map", map), ("reduce", reduce)]) command.update(**kwargs) response = self.__database._command(command) if full_response: return response return self.__database[response["result"]]
def transform_incoming(self, son, collection): """Move _id to the front if it's there. """ if not "_id" in son: return son transformed = SON({"_id": son["_id"]}) transformed.update(son) return transformed
def transform_incoming(self, son, collection): """Move _id to the front if it's there. """ if not "_id" in son: return son transformed = SON({"_id": son["_id"]}) transformed.update(son) return transformed
def __create(self, options): """Sends a create command with the given options. """ # Send size as a float, not an int/long. BSON can only handle 32-bit # ints which conflicts w/ max collection size of 10000000000. if "size" in options: options["size"] = float(options["size"]) command = SON({"create": self.__collection_name}) command.update(options) self.__database._command(command)
def __create(self, options): """Sends a create command with the given options. """ # Send size as a float, not an int/long. BSON can only handle 32-bit # ints which conflicts w/ max collection size of 10000000000. if "size" in options: options["size"] = float(options["size"]) command = SON({"create": self.__collection_name}) command.update(options) self.__database._command(command)