Skip to content

Commit 67b4224

Browse files
authored
Merge pull request #13568 from Automattic/vkarpov15/gh-13548
docs(migrating_to_7): add mapReduce() removal to migration guide
2 parents d8d4845 + dd3955d commit 67b4224

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/migrating_to_7.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ If you're still on Mongoose 5.x, please read the [Mongoose 5.x to 6.x migration
2020
* [Copy schema options in `Schema.prototype.add()`](#copy-schema-options-in-schema-prototype-add)
2121
* [ObjectId bsontype now has lowercase d](#objectid-bsontype-now-has-lowercase-d)
2222
* [Removed support for custom promise libraries](#removed-support-for-custom-promise-libraries)
23+
* [Removed mapReduce](#removed-mapreduce)
2324
* [TypeScript-specific changes](#typescript-specific-changes)
2425
* [Removed `LeanDocument` and support for `extends Document`](#removed-leandocument-and-support-for-extends-document)
2526
* [New parameters for `HydratedDocument`](#new-parameters-for-hydrateddocument)
@@ -254,6 +255,25 @@ oid._bsontype; // 'ObjectId' in Mongoose 7, 'ObjectID' in older versions of Mong
254255
Please update any places where you use `_bsontype` to check if an object is an ObjectId.
255256
This may also affect libraries that use Mongoose.
256257

258+
<h2 id="removed-mapreduce"><a href="#removed-mapreduce">Removed mapReduce</a></h2>
259+
260+
MongoDB no longer supports `mapReduce`, so Mongoose 7 no longer has a `Model.mapReduce()` function.
261+
Use the aggregation framework as a replacement for `mapReduce()`.
262+
263+
```javascript
264+
// The following no longer works in Mongoose 7.
265+
const o = {
266+
map: function() {
267+
emit(this.author, 1);
268+
},
269+
reduce: function(k, vals) {
270+
return vals.length;
271+
}
272+
};
273+
274+
await MR.mapReduce(o);
275+
```
276+
257277
<h2 id="removed-support-for-custom-promise-libraries"><a href="#removed-support-for-custom-promise-libraries">Removed Support for custom promise libraries</a></h2>
258278

259279
Mongoose 7 no longer supports plugging in custom promise libraries. So the following no longer makes Mongoose return Bluebird promises in Mongoose 7.

0 commit comments

Comments
 (0)