[英]MongoDB 2.4 MapReduce Refactor
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. 我最近升级到MongoDB 2.4,并且如发行说明中所述,使用db的map函数存在问题。 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. 由于不建议使用db,因此我不清楚如何将文档从“学生”集合传递到“学生”变量。
Any recommendations? 有什么建议吗?
You can no longer run a query inside a javascript function anymore. 您不再可以在javascript函数内运行查询。
See: http://docs.mongodb.org/manual/release-notes/2.4/#additional-limitations-for-map-reduce-and-where-operations 请参阅: http : //docs.mongodb.org/manual/release-notes/2.4/#additional-limitations-for-map-reduce-and-where-operations
You can pass data into the scope eg: 您可以将数据传递到范围内,例如:
res = t.mapReduce( mapper , reducer , { scope : { xx : 1 } } );
But as to how bigger a refactor - it depends on what the original map reduce function did. 但是关于重构的大小-它取决于原始映射的reduce函数的作用。
You may want to collate all the data needed into a new collection and then run the map reduce over that instead. 您可能需要将所有需要的数据整理到一个新集合中,然后运行map reduce来代替它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.