I am working on a task where i am taking the id generated from the database collection and i passing it through the postman.. i am converting that it to database obejct id created and its working accordinlg if we pass correct id else it is throwing an error
mongo.get().collection("post").find({"_id":new ObjectId(req.headers.postid)}).toArray(function(err, result) {
if (err) throw err;
if(result.length==0){
jsonObj.response="post id entered is invalid ";
res.send(jsonObj)
}
else{
//some operations
}
}
when ever i am not passing the valid input it is throwing the following error
<body>
<h1>Argument passed in must be a single String of 12 bytes or a string of 24 hex characters</h1>
<h2></h2>
<pre>Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters
at new ObjectID (/home/vamsi/nodejs-training/myfirstproject/facebook/node_modules/bson/lib/bson/objectid.js:51:11)
at Object.handle (/home/vamsi/nodejs-training/myfirstproject/facebook/routes/updatepost.js:36:47)
at next_layer (/home/vamsi/nodejs-training/myfirstproject/facebook/node_modules/express/lib/router/route.js:103:13)
at Route.dispatch (/home/vamsi/nodejs-training/myfirstproject/facebook/node_modules/express/lib/router/route.js:107:5)
at /home/vamsi/nodejs-training/myfirstproject/facebook/node_modules/express/lib/router/index.js:195:24
at Function.proto.process_params (/home/vamsi/nodejs-training/myfirstproject/facebook/node_modules/express/lib/router/index.js:251:12)
at next (/home/vamsi/nodejs-training/myfirstproject/facebook/node_modules/express/lib/router/index.js:189:19)
at Function.proto.handle (/home/vamsi/nodejs-training/myfirstproject/facebook/node_modules/express/lib/router/index.js:234:5)
at Layer.router (/home/vamsi/nodejs-training/myfirstproject/facebook/node_modules/express/lib/router/index.js:23:12)
at trim_prefix (/home/vamsi/nodejs-training/myfirstproject/facebook/node_modules/express/lib/router/index.js:226:17)</pre>
</body>
</html>
new ObjectIdand so an exception is thrown. What would you want to happen instead?