Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your map function takes one parameter: <code>number</code>, which, when called by map-reduce, will be set to null and after coertion (and some <code>%</code> by zero) will make the date your map is returning <code>ISODate("0NaN-NaN-NaNTNaN:NaN:NaNZ")</code>. This after type conversion becomes <code>datetime.datetime(1970, 1, 1, 0, 0)</code>.</p> <p>Remove the parameter and it should work.</p> <p><strong>edit</strong></p> <p>To confirm that, try running this code:</p> <pre><code>from pymongo import Connection from bson.code import Code db = Connection().mr_test for i in xrange(10): db.things.insert({"x" : i}) map = Code("function(number) {" "emit({" "ts : number" "}, 1);" "}") reduce = Code("function(key, vals) {" "var sum = 0;" "for (var i in vals) {" "sum += vals[i]" "}" "return sum;" "}") result = db.things.map_reduce(map, reduce, "test_results") for doc in result.find(): print doc </code></pre> <p>The result on my machine is :</p> <pre><code>{u'_id': {u'ts': None}, u'value': 10.0} </code></pre> <p>Note that <code>ts</code> is <code>None</code> in the result, cause <code>number</code> was not set when the mapping function executed.</p> <p><strong>edit 2</strong></p> <p>AFAIK the only way to pass a parameter to <code>map</code> is by using <code>scope</code> optional parameter in <code>map_reduce</code>, but then you'll have to remove it from map signature anyway.</p> <p>So by changing your map to:</p> <pre><code>map = Code("function() {" "emit({" "ts : new Date(new Date((this.ts - (this.ts % (60 * number))) * 1000).setSeconds(0))" "}, 1);" "}") </code></pre> <p>and by calling:</p> <pre><code>db.whatever.map_reduce(map, reduce, "collection_name", scope = {"number" : the_value_your_function_needs}) </code></pre> <p>you can get the result you want.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload