Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Unknown modifier: $pushAll" #17

Open
metju90 opened this issue Aug 4, 2018 · 8 comments
Open

"Unknown modifier: $pushAll" #17

metju90 opened this issue Aug 4, 2018 · 8 comments

Comments

@metju90
Copy link

metju90 commented Aug 4, 2018

When using mutating with addLyricToSong like the following query:

mutation {
  addLyricToSong(songId: "5b0d32945cc5987c7dac2170", content: "xxxx") {
    lyrics {
      content
      song {
        title
      }
    }
  }
}

you run in the following error:

{
  "data": {
    "addLyricToSong": null
  },
  "errors": [
    {
      "message": "Unknown modifier: $pushAll",
      "locations": [
        {
          "line": 45,
          "column": 3
        }
      ],
      "path": [
        "addLyricToSong"
      ]
    }
  ]
}

This problem is reported here: Automattic/mongoose#5574.

I will make a PR with the fix

@metju90
Copy link
Author

metju90 commented Aug 4, 2018

I see there is an open PR with this fix already

@PostIt59
Copy link

I stucked with this error for an hour and finally it was pretty simple. You just need to update the schema :
with the following parameter usePushEach : true

const SongSchema = new Schema({
  title: { type: String },
  user: {
    type: Schema.Types.ObjectId,
    ref: 'user'
  },
  lyrics: [{
    type: Schema.Types.ObjectId,
    ref: 'lyric'
  }]
}, {
  usePushEach : true
});

And change addLyric song.lyrics.push(lyric) to song.lyrics.push(lyrics.id):


SongSchema.statics.addLyric = function(id, content) {
  const Lyric = mongoose.model('lyric');

  return this.findById(id)
    .then(song => {
      const lyric = new Lyric({ content, song })
      song.lyrics.push(lyric.id)
      return Promise.all([lyric.save(), song.save()])
        .then(([lyric, song]) => song);
    });
}

@isaaclem
Copy link

isaaclem commented Sep 7, 2018

@PostIt59 👍 Thanks for the effort but do note that there is a small typo. Instead of song.lyrics.push(lyrics.id), it should be song.lyrics.push(lyric.id). It's id of particular lyric

@csilva2810
Copy link

I had the same problem! What i Did was I added the option to the song schema usePushEach with the value true

const SongSchema = new Schema({
  title: { type: String },
  user: {
    type: Schema.Types.ObjectId,
    ref: 'user'
  },
  lyrics: [{
    type: Schema.Types.ObjectId,
    ref: 'lyric'
  }]
}, {
  usePushEach : true
});

@pglezen
Copy link

pglezen commented Oct 29, 2018

Another solution being floated in the Q & A section of Stephen's course is to upgrade our Mongoose version.

you are having a driver issue, the $pushall function is a mongoose function that no longer works with the mongodb server running on mlabs. $pushall was deprecated at some point.

To fix, all you need to do is go into your package.json file ( in the server directory), go to dependencies , change mongoose to 5.3.3.

Rerun npm install, and then you should no longer get the $pushall error. As that mongoose code is wired to run with the mongodb server version on mlabs.

Several people (myself included) have reported success with this.

Q & A Post (requires Udemy login): /graphql-with-react-course/learn/v4/questions/5414558

patw0929 added a commit to patw0929/udemy-lyrical-graphql that referenced this issue Dec 19, 2018
@SergeySergienko
Copy link

SergeySergienko commented Jan 7, 2019

Automattic/mongoose#5924 (comment)

In server/models/song.js just add:

mongoose.plugin(schema => { schema.options.usePushEach = true });

after

const mongoose = require('mongoose');

and everything works.

@leonardocartaxo
Copy link

Automattic/mongoose#5924 (comment)

In server/models/song.js just add:

mongoose.plugin(schema => { schema.options.usePushEach = true });

after

const mongoose = require('mongoose');

and everything works.

Thank's man. It Solved a big issue on my app

@ahmedyounes
Copy link

can we have pull request for this merged .. please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants