Lyrical-GraphQL icon indicating copy to clipboard operation
Lyrical-GraphQL copied to clipboard

"Unknown modifier: $pushAll"

Open metju90 opened this issue 7 years ago • 8 comments

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: https://github.com/Automattic/mongoose/issues/5574.

I will make a PR with the fix

metju90 avatar Aug 04 '18 13:08 metju90

I see there is an open PR with this fix already

metju90 avatar Aug 04 '18 13:08 metju90

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);
    });
}

PostIt59 avatar Aug 17 '18 08:08 PostIt59

@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

isaaclem avatar Sep 07 '18 09:09 isaaclem

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
});

csilva2810 avatar Oct 21 '18 00:10 csilva2810

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

pglezen avatar Oct 29 '18 01:10 pglezen

https://github.com/Automattic/mongoose/issues/5924#issuecomment-416966869

In server/models/song.js just add:

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

after

const mongoose = require('mongoose');

and everything works.

SergeySergienko avatar Jan 07 '19 12:01 SergeySergienko

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

leonardocartaxo avatar Aug 11 '19 23:08 leonardocartaxo

can we have pull request for this merged .. please

ahmedyounes avatar Apr 19 '20 21:04 ahmedyounes