We usually have this kind of error while making query with mongodb "Uncaught exception 'MongoException' with message 'Invalid object ID'" ,
the main reason behind this kind of error is that :->
a) Id string for mongodb must be 24 hexadecimal characters. If an invalid string is passed to this constructor, the constructor will ignore it and create a new id value.
Thus to solve this kind of error we can try something like this :
$_id = "-6";
try {
$_id = new MongoId($_id);
} catch (MongoException $ex) {
$_id = new MongoId();
}
0 Comment(s)