Answers for "casterror","message":"cast to objectid failed for value"

Lua
3

Cast to ObjectId failed for value

// it happens when you pass an invalid id to mongoose. 
// so first check it before proceeding, using mongoose isValid function

import mongoose from "mongoose";

// add this inside your route
if( !mongoose.Types.ObjectId.isValid(id) ) return false;
Posted by: Guest on October-18-2020
1

Cast to ObjectId failed for value

import mongoose from "mongoose";

// add this inside your route
if( !mongoose.Types.ObjectId.isValid(id) ) return false;
Posted by: Guest on October-18-2020

Code answers related to "casterror","message":"cast to objectid failed for value"

Browse Popular Code Answers by Language