const mongoose = require('mongoose'); console.log(mongoose.Types.ObjectId.isValid('53cb6b9b4f4ddef1ad47f943')); // true console.log(mongoose.Types.ObjectId.isValid('whatever')); // false