Skip to content

Commit 8d606e7

Browse files
committed
Replace .push with .concat to port to Mongodb 4
Otherwise actions such as commenting fail with: Unknown modifier: $pushAll As per: https://stackoverflow.com/questions/48607918/mongoerror-unknown-modifier-pushall-in-node-js/50435618#50435618 Fix #57 Fix #96 Fix #64
1 parent ba04b70 commit 8d606e7

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

models/User.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ UserSchema.methods.toProfileJSONFor = function(user){
6060

6161
UserSchema.methods.favorite = function(id){
6262
if(this.favorites.indexOf(id) === -1){
63-
this.favorites.push(id);
63+
this.favorites = this.favorites.concat([id]);
6464
}
6565

6666
return this.save();
@@ -79,7 +79,7 @@ UserSchema.methods.isFavorite = function(id){
7979

8080
UserSchema.methods.follow = function(id){
8181
if(this.following.indexOf(id) === -1){
82-
this.following.push(id);
82+
this.following = this.following.concat([id]);
8383
}
8484

8585
return this.save();

routes/api/articles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ router.post('/:article/comments', auth.required, function(req, res, next) {
254254
comment.author = user;
255255

256256
return comment.save().then(function(){
257-
req.article.comments.push(comment);
257+
req.article.comments = req.article.comments.concat([comment]);
258258

259259
return req.article.save().then(function(article) {
260260
res.json({comment: comment.toJSONFor(user)});

0 commit comments

Comments
 (0)