Monday 30 September 2019

Need some help with getting value out of .save() function with Mongoose

Hey,I have written the following code:module.exports = (parent, args, context, info) => { let mutationReturn; mongoose.connect(config.MONGO_DB_URL) var db = mongoose.connection db.on('error', console.error.bind(console, 'connection error:')); db.once('open', () => { console.log('Connection successful!') const Race = mongoose.model('Race', RaceSchema, 'RaceStore') const clientRace = new Race(args.race) clientRace.save().then(race => { mutationReturn = { id: race._id, name: race.name, naturalAttributes: race.naturalAttributes, skill: race.skill } }) }) return mutationReturn } The variable mutationReturn is always undefined. I'm not amazing with Promises, could I have some help getting this to work, please?

Submitted September 30, 2019 at 03:49PM by K9_Morphed

No comments:

Post a Comment