My code was working fine but after taking fresh code I am getting this error but as I can see my id is valid Object Id
Cast to ObjectId
You have to cast the data to mongodb object id. If you are using mongoose, you can actually do these below.
const mongoose = require('mongoose');
const ObjectId = mongoose.Types.ObjectId;
[your_mongodb_model/collection].query({ _id: ObjectId(id) });
or simply, you can do these,
[your_mongodb_model].query({ _id: mongoose.Types.ObjectId(id) });
The reason for this error is documented in this mongoose issue. A workaround is to downgrade to mongoose version <= 4.7.2 or use Node version >=6.