Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

90
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda