To fix can’t find documents searching by ObjectId using Node Mongoose, we convert the object ID string to an object ID.
For instance, we write
const ObjectId = require("mongoose").Types.ObjectId;
const query = { campaign_id: new ObjectId(campaign._id) };
to set query
to an object with the campaign+id
to an object ID that we create by calling the ObjectId
constructor with the campaign._id
string.