Can’t find documents searching by ObjectId using Mongoose

A couple tips:

  • Try running the same query from mongodb at the command line, see if you get any results.
  • Is the “campaign_id” defined as an ObjectId in your schema? If so, try searching using the ObjectId type.

For example:

var ObjectId = require('mongoose').Types.ObjectId; 
var query = { campaign_id: new ObjectId(campaign._id) };

Leave a Comment