Skip to content

Commit

Permalink
Replace .push with .concat to port to Mongodb 4
Browse files Browse the repository at this point in the history
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 gothinkster#57
Fix gothinkster#96
Fix gothinkster#64
  • Loading branch information
cirosantilli committed Mar 22, 2021
1 parent ba04b70 commit 73c793d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion routes/api/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)});
Expand Down

0 comments on commit 73c793d

Please sign in to comment.