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

91
Vistas
Trying to push data from a object n mongo

So when fiddling with data in mongo using mongoose I am having a difficult time with setting data to a document

This issue is when I use $set in findByIdAndUpdate it sets the entire document to when I put it in, which is bad.

So then I did some research and I tried using $push from a previous project but it turns out that $push doesn't work in the array (Makes sense)

So then how would I both $set data to a document that only updates the fields to which I am updating data?

This may seem like a simple question but I am not the best problem solver, with mongooses documents not being the best I struggle to find a lot of answers to my problems in the documents

This is the code I have in my Code Base

await userSchema.findByIdAndUpdate(attackerUser._id, { $push : { duelInfo: { dueling: false, duelingWith: "", timeSinceOffer: 0} }, $inc : { duelinfo: { wins : 1 }, credits : user.duelInfo.duelBet } }, { upsert : true } );
            await userSchema.findByIdAndUpdate(attackerUser._id, { $inc : { duelinfo: { wins : 1 }, credits : user.duelInfo.duelBet } }, { upsert : true } );
            await userSchema.findByIdAndUpdate(defenderUser._id, { $push : { duelInfo: { dueling: false, duelingWith: "", timeSinceOffer: 0} } }, { upsert : true } );
            await userSchema.findByIdAndUpdate(defenderUser._id, { $inc : { duelinfo: { losses : 1 } }, credits : - user.duelInfo.duelBet }, { upsert : true } );

This is what the Documents look like

_id: "195967294"
username:"emansza"
collectInfo: true
credits: 5000
processSign: false
messageCount: 0
duelInfo:Object
    dueling: false
    duelingWith: ""
    lastDuel: 2022-01-06T02:09:46.340+00:00
    wins: 1
    losses: 1
    draws: 1
    duelBet: 1
about 4 years ago · Juan Pablo Isaza
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