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

260
Views
Mongoose "Query was already executed" exception

I updated mongoose to latest version and this error occurs. In this example new user is being created and his data is to be added to an existing user. the user is created but no longer adds his information to the second. The first time a function was called, it was added and no more.

My code:

const member_reg_post = async (req, res) => {
    var { parentID, login, password, fname, surname, age=null } = req.body;

    try {
        const isAdult = false;
        const user = await User.create({ login, password, fname, surname, isAdult });
        const member = await {
            _id: user._id,
            fname: user.fname
        };
        console.log(member);
        const memberAdd = await User.updateOne(
            { _id: parentID },
            { $addToSet: { familyMembers: member }},
            (err) => {
                if (err) {
                    console.log(err);
                    res.status(400).json({ operationStatus: 'Failed'});
                } else {
                    res.status(201).json({ operationStatus: 'Completed'});
                }
            }
        );

        console.log('member_reg_post -> job done');
        res.status(200).json(user);
    } catch (err) {
        console.log(err);
    }
};

Error:

MongooseError: Query was already executed: user.updateOne({ _id: new ObjectId("6197d747ce81ffb8d214eaa5...
    at model.Query._wrappedThunk [as _updateOne] (C:\Users\Dawid\Desktop\homequest\node_modules\mongoose\lib\helpers\query\wrapThunk.js:21:19)
    at C:\Users\Dawid\Desktop\homequest\node_modules\kareem\index.js:370:33
    at processTicksAndRejections (internal/process/task_queues.js:79:11) {
  originalStack: 'Error\n' +
    '    at model.Query._wrappedThunk [as _updateOne] (C:\Users\Dawid\Desktop\homequest\node_modules\mongoose\lib\helpers\query\wrapThunk.js:25:28)\n' +
    '    at C:\Users\Dawid\Desktop\homequest\node_modules\kareem\index.js:370:33\n' +
    '    at processTicksAndRejections (internal/process/task_queues.js:79:11)'
}
about 4 years ago · Juan Pablo Isaza
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!