controllers/thoughtController.js
//POST to create new thought -> push its id to user's thoughts field
POST to create new thought -> push its id to user's thoughts field
POST to create new thought - > push its id to user ' s thoughts field
createThought({ body }, res) {
          console.log('body', body);
          Thought.create(body)
          .then(dbThoughtData => {
               console.log('THOUGHTDATA', {dbThoughtData});
               console.log('USER ID', body.userId);
               return User.findOneAndUpdate(
                    { _id: body.userId },
                    { $push: { thoughts: dbThoughtData._id } },
                    { new: true }
               );
          })
          .then(dbUser => {
               console.log('DBUSER', {dbUser});
               if (!dbUser) {
                    return res.status(404).json({ message: 'No user found with that id.' });
               }
               res.json(dbUser);
          })
          .catch(err => {
               console.log('ERROR LOG', err);
               res.json(err);
          });
     }
createThought ( { body } , res ) { console . log ( 'body' , body ) ; Thought . create ( body ) . then ( dbThoughtData => { console . log ( 'THOUGHTDATA' , { dbThoughtData } ) ; console . log ( 'USER ID' , body . userId ) ; return User . findOneAndUpdate ( { _id : body . userId } , { $push : { thoughts : dbThoughtData . _id } } , { new : true } ) ; } ) . then ( dbUser => { console . log ( 'DBUSER' , { dbUser } ) ; if ( ! dbUser ) { return res . status ( 404 ) . json ( { message : 'No user found with that id.' } ) ; } res . json ( dbUser ) ; } ) . catch ( err => { console . log ( 'ERROR LOG' , err ) ; res . json ( err ) ; } ) ; }
POST to create new thought -> push its id to user's thoughts field
POST to create new thought - > push its id to user ' s thoughts field