Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

206
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda