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

The add lyrics query returns an error but saves in the database #30

Open
Jay-Topher opened this issue Jan 21, 2020 · 9 comments
Open

The add lyrics query returns an error but saves in the database #30

Jay-Topher opened this issue Jan 21, 2020 · 9 comments

Comments

@Jay-Topher
Copy link

error

I believe there's an issue either with the db model or the addLyrics mutation

@vishalisakar
Copy link

yes. I'm also having the same issue.

@Jay-Topher
Copy link
Author

Jay-Topher commented Jan 22, 2020

Anyone with answers should please notify us here, so we can move forward with the course, this is a huge blocker

@levelingup
Copy link

levelingup commented Feb 8, 2020

How far along are you in the video?

@Jay-Topher
Copy link
Author

I'm currently in Client side graphql >> working through the schema

@Jay-Topher
Copy link
Author

That should be the fourth video of the 6th section

@levelingup
Copy link

levelingup commented Feb 17, 2020

So you cloned the repo, are you using monogodb atlas? https://www.mongodb.com/cloud/atlas

@vishalisakar
Copy link

vishalisakar commented Feb 18, 2020

Finally, I got the solution.
Thank you @PostIt59, by your solution only I could solve it.

I hope u can try this or you can check his solution in issue page at #17

In server/models/song.js just add:

usePushEach : true

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

then change the addLyric as follows

song.lyrics.push(lyric) to song.lyrics.push(lyric.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);
    });
}


@Jay-Topher
Copy link
Author

Yes @levelingup , I'm using mongoDB Atlas, thanks @vishalisakar for the update, I'll try it now

@Jay-Topher
Copy link
Author

Thanks guys, it worked. Now I can move on with the course, I think I should leave this here for people who would run into this problem so they can find the solution here

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

3 participants