let objectIdArray = stringObjectIdArray.map(s => mongoose.Types.ObjectId(s));
//or
let objectIdArray = stringObjectIdArray.map(mongoose.Types.ObjectId);
function toObjectId(ids) {
if (ids.constructor === Array) {
return ids.map(mongoose.Types.ObjectId);
}
return mongoose.Types.ObjectId(ids);
}