Skip to content

uncaught TypeError on countDocuments with invalid query. #6843

@0xF48

Description

@0xF48
#!/usr/bin/env node --no-deprecation
'use strict';

const moment = require('moment');
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
const conn = mongoose.connection;
const Schema = mongoose.Schema;

const schema = new Schema({
  name: String,
  createdAt: Date
});

const Test = mongoose.model('test', schema);

const tests = [];

for (let i = 1; i <= 100; i++) {
  let date = moment().subtract(i, 'days');
  tests.push(new Test({ name: `name${i}`, createdAt: date }));
}

async function run() {
  await conn.dropDatabase();
  await Test.create(tests);
  const start = moment().subtract(50, 'days').startOf('day');
  const cutoff = moment().endOf('day');
  try{
    const result = await Test.countDocuments({
      $invalid: start
    })
  }catch(e){
    console.log('caught error')
    console.error(e)
  }
  
  console.log(result);
  return conn.close();
}

run();
TypeError: callback is not a function

Metadata

Metadata

Assignees

No one assigned

    Labels

    underlying library issueThis issue is a bug with an underlying library, like the MongoDB driver or mongodb-core

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions