Argument passed in must be a single String of 12 bytes or a string of 24 hex characters

2,300 views
Skip to first unread message

Md Ashiqur Rahman

unread,
Nov 29, 2017, 4:36:38 PM11/29/17
to nodejs
how to resolve this error:- Argument passed in must be a single String of 12 bytes or a string of 24 hex characters.

ProjectSubmit.findOne({'_id': ObjectId.createFromHexString(req.params.id)}).then((projectSubmit)=>{
res.render('main/proposal-des', {title: req.params.projectName, projectSubmit: projectSubmit});
// res.render('proposalList', { title: 'Synergy Proposal List'});
}, (e) => {
res.status(404).send(e);
});


when logout url hit this error occured 

nat...@burchill.io

unread,
Dec 11, 2017, 5:42:15 PM12/11/17
to nodejs
Instead of converting req.params.id to an ObjectId try just passing in the string. That seems to be what it is expecting.

Also if this is mongoose and you're querying using the Model object then you can use findById. Your way isn't wrong and it will work fine but findById may be more readable.

ProjectSubmit.findById(req.params.id).then((projectSubmit)=>{
 res.render('main/proposal-des', {title: req.params.projectName, projectSubmit: projectSubmit});
}, (e) => {
  res.status(404).send(e);
});
Reply all
Reply to author
Forward
0 new messages