title: (node:19677) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'find' of undefined
body: <p>I am currently working on a backend to a wishlist and I have been having this issue with my code</p>
  <pre><code>(node:19677) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'find' of undefined
  </code></pre>
  <p>I have tried redefining the wishlist import and even the user import but to no fix.</p>
  <p>Below is my code for my wishlist at the moment.</p>
  <pre><code> import mongoose from 'mongoose';
  import express from 'express';
  import wishlist from '../models/wishlist_model.js';
  import User from '../models/user_model.js';
  import { BooksSchema } from '../models/books_model';
  import { wishlistSchema } from '../models/wishlist_model';
  
  
  const Books = mongoose.model('Books', BooksSchema);
  const app = express();
  
  
  app.use(express.json());
  
  
  //Create a wishlist
  export const createWishlist = async (req, res, next) =&gt; {
      const wishOwner = await User.find({&quot;username&quot; : `${req.body.username}`})
      .exec()
      .then(user =&gt;{
             if (user != 0) {
              const wish = new wishlist({
                  wishlist_id: mongoose.Types.ObjectId(),
                  _id: user[0]._id,
                  username: req.body.username
              });
              wish.save().then(result=&gt;{
                  console.log(result);
                  res.status(201).json({
                      msg: `Wishlist created for ${req.body.username}`
                  })
              })
          }
          else{
              return res.status(400).json({msg:  &quot;User does not exist&quot;});
          }
              
      });
  };
  
  
  //Add units to Wishlist
  
  export const addToWishlist = async (req, res, next) =&gt; {
      let bookToAdd = await Books.find({&quot;isbn&quot; : `${req.query.isbn}`},{&quot;title&quot; : 1 , &quot;price&quot; : 1}).exec()
      let bookTitle =  bookToAdd[0].title;
      let wishOwner = await User.find({&quot;username&quot; : `${req.query.username}`}).exec()
      let wishlist = await wishlist.find({&quot;username&quot; : `${req.query.username}`}).exec()
      let newWishBooks = wishlist[0].books;
      newWishBooks.push(bookTitle);
  
  
      await wishlist.updateOne( { &quot;username&quot;: `${req.query.username}` },
      {
        $set: {
          books: newWishBooks
        }});
  
  
      res.json({ 
          msg: `Successfully added ${bookTitle} to ${wishOwner[0].username}'s Wishlist!`
      }
      );
  }
  </code></pre>
  <p>Any help would be appreciated!
  Thank you</p>