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

207
Views
MongoServerError: Cannot create field 'count' in element

When the database matches the below value then I want to increase the count by 1.

const inr = await Postproduct.updateOne({"uid":123456,"userclick.email":"neelshah486@gmail.com"},{$inc: { "userclick.count": 1}})

But right now I'm getting the following error while doing so. Error

And this is my database

MongoDB Output

Kindly help me with the same. What I want to do is every time the user clicks the button. I want the count to increase by 1.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Since userclick is an array, you will need to use an array operator for updating just the one element.

In this case, since the query uniquely identifies one element, you can use the $ positional operator, like:

await Postproduct.updateOne(
    {"uid":123456,"userclick.email":"neelshah486@gmail.com"},
    {$inc: { "userclick.$.count": 1}}
)
about 4 years ago · Juan Pablo Isaza Report

0

You can set default value of count to zero. like this :

userClicks:[{
count:{type:Number,default:0,},
email:String,
satisfy:String,
amount:Number,
          }]
about 4 years ago · Juan Pablo Isaza 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!