Answers for "cast to objectid failed for value "[ ]" (type string) at path "_id" for model "user""

Lua
0

CastError: Cast to ObjectId failed for value "undefined" at path "_id" for model

// 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 June-30-2021
1

CastError: Cast to ObjectId failed for value "undefined" at path "_id" for model

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 "cast to objectid failed for value "[ ]" (type string) at path "_id" for model "user""

Browse Popular Code Answers by Language