MongoDB: Cannot do inclusion on field 'guides' in exclusion projection

I got some error that says 'Cannot do inclusion on field guides in exclusion projection', this happen bcs I tried to populate data using pre middleware in my schema:

const tourSchema = new mongoose.Schema({
 guides: [
      type: mongoose.Schema.ObjectId,
      ref: 'User'

tourSchema.pre(/^find/, function(next) {
  this.populate({ path: 'guides' });

but the error happen only when accessing getAllTour handlers when access only specified tour the error does not showed up

// Errors happens here
exports.getAllTours = catchAsync(async (req, res, next) => {
  const features = new APIFeatures(Tour.find(), req.query)
  const tours = await features.query;
    status: 'success',
    length: tours.length,
    data: {
// But in here there is no error
exports.getTour = catchAsync(async (req, res, next) => {
  const tour = await Tour.findById(;
  if (!tour) {
    return next(
      new AppError('No tour found! please check the ID correctly', 404)
    status: 'success',
    requestedAt: req.requestTime,
    data: {

you can also check my code in this link

Solutions for my errors


  • After debugging my code from previous answer, the errors is gone by made little bit changes from limitFields():

    else if (this.queryString._fieldsForExec) {
          const fields = this.query
            .filter(f => !['createdAt', '_id', '__v'].includes(f));
          this.query =;
        return this;

    by adding this.queryString._fieldsForExec as a parameter, this can get rid of the undefined from .filter.