Mongoose CastError when using $in with ObjectId array on referenced field

const employees = await BasicEmployee.collection
.find({ login_id: { $in: loginIds } })
.toArray();

i was able to use $in using collection but why it is not working without collection ?