title: BSONTypeError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters
body: <p>Need some help here.
  Tried almost everything that I found at the internet, but didn't works.</p>
  <p>So, this is my code:</p>
  <pre><code>    const id = req.params.id.trim(); 
      Blog.findById(id)
          .then((result) =&gt; {
              res.render(&quot;details&quot;, { blog: result, title: &quot;Blog Details&quot; });
          })
          .catch((err) =&gt; {
              console.log(err);
          });
  };
  </code></pre>
  <p>it's happens when I'm trying to create a new blog.</p>
  <p><strong>this is my error :</strong></p>
  <pre><code>
  CastError: Cast to ObjectId failed for value &quot;blogs&quot; (type string) at path &quot;_id&quot; for model &quot;Blog&quot;
      at model.Query.exec (/Users/xxx/blogMongoDB/node_modules/mongoose/lib/query.js:4546:21)
      at model.Query.Query.then (/Users/xxx/blogMongoDB/node_modules/mongoose/lib/query.js:4645:15)
      at blog_details (/Users/xxx/blogMongoDB/controllers/blogController.js:19:10)
      at Layer.handle [as handle_request] (/Users/xxx/blogMongoDB/node_modules/express/lib/router/layer.js:95:5)
      at next (/Users/xxx/blogMongoDB/node_modules/express/lib/router/route.js:137:13)
      at Route.dispatch (/Users/xxx/blogMongoDB/node_modules/express/lib/router/route.js:112:3)
      at Layer.handle [as handle_request] (/Users/xxx/blogMongoDB/node_modules/express/lib/router/layer.js:95:5)
      at /Users/xxx/blogMongoDB/node_modules/express/lib/router/index.js:281:22
      at param (/Users/xxx/blogMongoDB/node_modules/express/lib/router/index.js:354:14)
      at param (/Users/xxx/blogMongoDB/node_modules/express/lib/router/index.js:365:14) {
    messageFormat: undefined,
    stringValue: '&quot;blogs&quot;',
    kind: 'ObjectId',
    value: 'blogs',
    path: '_id',
    reason: BSONTypeError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters
        at new BSONTypeError (/Users/xxx/blogMongoDB/node_modules/bson/lib/error.js:41:28)
        at new ObjectId (/Users/xxx/blogMongoDB/node_modules/bson/lib/objectid.js:65:23)
        at castObjectId (/Users/xxx/blogMongoDB/node_modules/mongoose/lib/cast/objectid.js:25:12)
        at ObjectId.cast (/Users/xxx/blogMongoDB/node_modules/mongoose/lib/schema/objectid.js:245:12)
        at ObjectId.SchemaType.applySetters (/Users/xxx/blogMongoDB/node_modules/mongoose/lib/schematype.js:1135:12)
        at ObjectId.SchemaType._castForQuery (/Users/xxx/blogMongoDB/node_modules/mongoose/lib/schematype.js:1567:15)
        at ObjectId.SchemaType.castForQuery (/Users/xxx/blogMongoDB/node_modules/mongoose/lib/schematype.js:1557:15)
        at ObjectId.SchemaType.castForQueryWrapper (/Users/xxx/blogMongoDB/node_modules/mongoose/lib/schematype.js:1534:20)
        at cast (/Users/xxx/blogMongoDB/node_modules/mongoose/lib/cast.js:336:32)
        at model.Query.Query.cast (/Users/xxx/blogMongoDB/node_modules/mongoose/lib/query.js:4969:12),
    valueType: 'string'
  }
  </code></pre>