2

I recently upgraded to MongoDB 2.4 and as referenced in the release notes, am having an issue with a map function that makes use of db. The release notes recommend refactoring, but I am unclear as to what route I need to take.

The now non-working piece of the function is as follows:

function map() {
  var student = db.student.findOne(this.student_id);
  var school = db.school.findOne(this.school_id);
  ...
  emit({
    bcg_id: student.bcg_id,
  ...

I am unclear on how to pass the document from the 'student' collection to the 'student' variable now that db is deprecated.

Any recommendations?

4

1 回答 1

1

您不能再在 javascript 函数中运行查询。

请参阅:http ://docs.mongodb.org/manual/release-notes/2.4/#additional-limitations-for-map-reduce-and-where-operations

您可以将数据传递到范围内,例如:

res = t.mapReduce( mapper , reducer , { scope : { xx : 1 } } );

但至于重构有多大——这取决于原始 map reduce 函数做了什么。

您可能希望将所需的所有数据整理到一个新集合中,然后对其运行 map reduce。

于 2013-03-27T13:42:13.020 回答