Sam is correct. In your example with only one document there isn't
anything to reduce. If you try your example in the mongo shell you
will get the same result. If you need to do any kind of post-
> Reduce will not run on a single document.
> I am not sure why you need reduce to run on a single document since it just
> designed to combine emitted data really...you finalize function does
> post-processing stuff.
> On 2 July 2011 23:57, james <jmslee...@gmail.com> wrote:
> > Hi,
> > I'm using the Python driver with v 1.8.1.
> > Having trouble getting reduce to work when there's only 1 document to
> > reduce. No problems at all when there are >1 document to reduce for a
> > given key.
> > Here's an example illustrating my problem:
> > Source collection - "source-mr"
> > Output collection - "out-mr"
> > SOURCE COLLECTION
> > ----------------------------------
> > > db["source-mr"].find()
> > { "_id" : ObjectId("4e0f9c948d4528c39aee706c"), "x" : 1 }
> > MAP REDUCE CODE
> > ----------------------------------
> > m = Code("function() { "
> > " emit(this.x, 1);"
> > "}");
> > r = Code("function(key, values) {"
> > " return 2;"
> > "}");
> > res = db["source-mr"].map_reduce(m, r, query={}, out="out-mr")
> > OUTPUT COLLECTION
> > ----------------------------------
> > > db["out-mr"].find()
> > { "_id" : 1, "value" : 1 }
> > Reduce is not running or else I would see {"value": 2} in the output
> > collection. If I add another document to my source collection with
> > the same key ("x": 1), reduce runs properly and I see {"value": 2} in
> > my output collection.
> > Thanks in advance for your help.
> > James
> > --
> > You received this message because you are subscribed to the Google Groups
> > "mongodb-user" group.
> > To post to this group, send email to mongodb-user@googlegroups.com.
> > To unsubscribe from this group, send email to
> > mongodb-user+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/mongodb-user?hl=en.