From 73c793d068d26b4859d10aa946b7b86a6eb6426a Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Mon, 22 Mar 2021 18:15:01 +0000 Subject: [PATCH] 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 Tested on Ubuntu 20.10, Mongo 4.4.4, https://github.com/gothinkster/vue-realworld-example-app at 61742206c170db02b04d63c7e9d43807d8c6b902 with only the URL modified: diff --git a/src/common/config.js b/src/common/config.js index 03af84e..ccd9c4d 100644 --- a/src/common/config.js +++ b/src/common/config.js @@ -1,2 +1,2 @@ -export const API_URL = "https://conduit.productionready.io/api"; +export const API_URL = "http://localhost:3000/api"; export default API_URL; Fix https://github.com/gothinkster/node-express-realworld-example-app/issues/57 Fix https://github.com/gothinkster/node-express-realworld-example-app/issues/96 Fix https://github.com/gothinkster/node-express-realworld-example-app/issues/64 --- models/User.js | 4 ++-- routes/api/articles.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/models/User.js b/models/User.js index cb6c0f2b0..37558d1da 100644 --- a/models/User.js +++ b/models/User.js @@ -60,7 +60,7 @@ UserSchema.methods.toProfileJSONFor = function(user){ UserSchema.methods.favorite = function(id){ if(this.favorites.indexOf(id) === -1){ - this.favorites.push(id); + this.favorites = this.favorites.concat([id]); } return this.save(); @@ -79,7 +79,7 @@ UserSchema.methods.isFavorite = function(id){ UserSchema.methods.follow = function(id){ if(this.following.indexOf(id) === -1){ - this.following.push(id); + this.following = this.following.concat([id]); } return this.save(); diff --git a/routes/api/articles.js b/routes/api/articles.js index e0f1074ba..c17ca6145 100644 --- a/routes/api/articles.js +++ b/routes/api/articles.js @@ -254,7 +254,7 @@ router.post('/:article/comments', auth.required, function(req, res, next) { comment.author = user; return comment.save().then(function(){ - req.article.comments.push(comment); + req.article.comments = req.article.comments.concat([comment]); return req.article.save().then(function(article) { res.json({comment: comment.toJSONFor(user)});