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

238
Views
i cannot use $set operator and $inc operator together only one is working in my case
const User = require('./model.js)

    const result = await User.updateMany({_id:{$in:team}},{ $set: { current_level_status : 'incomplete' , user_helper_status : false,user_admin_status : false }},{$inc:{level_number:1}});
console.log(result)

i am using mongoose set operator and increment operator together

mongoose 'updateMany' is not working with this operators team field contains array of object ids

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

https://mongoosejs.com/docs/api.html#model_Model.updateMany

  1. filter «Object»
  2. doc «Object»
  3. [options] «Object» optional see Query.prototype.setOptions()

The problem is you're passing $inc in the 3rd parameter instead of joining it with same object inside 2nd parameter.


Change

const result = await User.updateMany(
 {_id:{$in:team}}, // Parameter 1
 {$set: { current_level_status : 'incomplete' , user_helper_status : false,user_admin_status : false }}, // Parameter 2
 {$inc:{level_number:1}} // Parameter 3
);

To

const result = await User.updateMany(
 {_id:{$in:team}}, // Parameter 1
 { // Parameter 2
    $set: { current_level_status : 'incomplete' , user_helper_status : false,user_admin_status : false }
    $inc: {level_number:1}
 }
);

Demo - https://mongoplayground.net/p/7zHcJy_sh-H

over 4 years ago · Santiago Trujillo Report

0

$inc should be in second parameter of the update() function, but outside of the $set:

User.updateMany({ _id: { $in: team } }, { 
  $set: { 
    current_level_status: 'incomplete',
    user_helper_status: false,
    user_admin_status : false 
  },
  $inc: { level_number: 1 }
});
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!