You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BSONTypeError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer
at new BSONTypeError (/home/mtonon/Web Dev/mongodb-page/node_modules/bson/lib/error.js:41:28)
**at new ObjectId** (/home/mtonon/Web Dev/mongodb-page/node_modules/bson/lib/objectid.js:67:23)
at /home/mtonon/Web Dev/mongodb-page/routes/blog.js:28:20
Then I found a solution on forums, just use .trim() on const authorId to remove any extra blank space:
router.post('/posts', async function(req,res){
const authorId = new ObjectId(req.body.author.trim());
If someone is getting the same error, this worked for me!
The text was updated successfully, but these errors were encountered:
I was getting this error:
Then I found a solution on forums, just use .trim() on const authorId to remove any extra blank space:
If someone is getting the same error, this worked for me!
The text was updated successfully, but these errors were encountered: