Lyrical-GraphQL
Lyrical-GraphQL copied to clipboard
"Unknown modifier: $pushAll"
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
I see there is an open PR with this fix already
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 👍 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
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
});
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
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.
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
can we have pull request for this merged .. please