Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

443
Views
'MongooseError: Callback must be a function, got [object Object]' When using "updateMany" function

Ignore the messy code. I've been working for hours on end and haven't had time to organize it.

I keep getting this error everytime the messageCount is 100 or more.

const profileData = await Profiles.findOne({
    userID: message.author.id
});
if (!profileData) return console.log('re')
try {
    if (profileData.messageCount >= 100) {
        console.log('yeet')
        await Profiles.updateMany({
            userID: message.author.id
        }, {
            messageCount: 0,
        }, {
            $inc: {
                caseCount: +1
            }
        }, {
            upsert: true
        });
    } else {
        console.log('na')
    }
} catch (error) {
    console.log(error);
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The updateMany() method needs only 3 parameters, it expects the fourth parameter to be an optional callback function, but you used an object, which explains the error message.

Combine your set and inc parameters like this:

await Profiles.updateMany(
  {
    userID: message.author.id
  },
  {
    $set: { messageCount: 0 },
    $inc: { caseCount: 1 },
  },
  {
    upsert: true
  }
);

Check the docs for more information.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!