title: Getting null ObjectID from MongoDB using findByID in javascript - newbie
body: <p>I am new to javascript and mongo and trying to find a course in my MongoDB database collection using id but getting null. Could you please help me with this?</p>
  
  <p><strong>Note:</strong> I am using MacBook. This is a very basic thing I am trying to do. I am able to fetch the object using .find() but findByID(id) doesn't seem to work for me. What am I missing? Let me know if any more detail is required.</p>
  
  <p><strong>Edit:</strong> A weird observation, refer the <strong>image</strong>. For the first one, I cannot find it or update it using id but I could find and update the second one. The first one was inserted in database using json file and second one was inserted using .save() in javascript.</p>
  
  <p><strong>PFB my code:</strong></p>
  
  <pre><code>const mongoose = require('mongoose');
  
  mongoose.connect('mongodb://localhost/mongo-exercise', { useNewUrlParser: true, useUnifiedTopology: true })
      .then(() =&gt; console.log('Connected to mongo-exercise database.'))
      .catch(err =&gt; console.log('Could not connect to mongo-exercise database.', err));
  
  // Create the schema
  const schema = new mongoose.Schema({
      name: String,
      author: String,
      price: Number,
      tags: [String],
      isPublished: Boolean
  });
  
  // Call the schema
  const Course = mongoose.model('course', schema);
  
  async function updateCourse(id) {
      try {
          const course = await Course
              .findById(id);
          console.log('Course is ', course);
      }
      catch (err) {
          console.log('Solution failed: ', err.message);
          throw error
      }
  }
  
  updateCourse("5a68fdf95db93f6477053ddd");
  </code></pre>
  
  <p>[<img src="https://i.stack.imgur.com/88D8j.png" alt="enter image description here">]</p>