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

297
Views
errmsg: 'Unsupported projection option: $push: { ... }', code: 2, codeName: 'BadValue' }

I have a problem on debugging this error can you help me?

This is my code

router.post('/accounts/show_accounts/:id', function(req,res){
    Account.findOne(
        {_id:req.params.id},
        {$push: {team: {team_name: req.body.team_name}}},
        {safe: true, upsert: true},
        function(err, model) {
            console.log(err);
        }
    )
});

And I am getting the below error

errmsg: 'Unsupported projection option: $push: { team: { team_name: “hahaha” } }', code: 2, codeName: 'BadValue' }

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

As the error states, findOne() method considers the document { "$push": { "team": { "team_name": req.body.team_name } } } as a projection and in a projection field names do not start with $. I believe you want to do an update operation, not a query. In that case, you need to use the findOneAndUpdate() or findByIdAndUpdate() method because the $push operator is only used in an update operation, not a query like findOne():

router.post('/accounts/show_accounts/:id', function(req, res){
    Account.findByIdAndUpdate(
        req.params.id,
        { "$push": { "team": { "team_name": req.body.team_name } } },
        { "upsert": true, "new": true },
        function(err, model) {
            if (err) throw err;
            console.log(model);
        }
    )
});

NB: findByIdAndUpdate(id, ...) is equivalent to findOneAndUpdate({ _id: id }, ...)

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!