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

235
Visualizações
change only one field of entire array of embedded document in mongoose

i have a list schema and a question set schema. the quetsionSet schema is embedded inside the list schema. its working fine but how can i update anything inside the array of embedded document i.e. here i want to change the listname of all the documents inside questionSet (array of questionSet documents).

here is an example of my list document model

{ "_id" : ObjectId("60f2cc07275bbb30d8cb268e"), 
"listName" : "dsa", 
"aboutList" : "dsa queestions",
 questionSet" : [ { "solved" : false, 
                   "_id" : ObjectId("60f2cc12275bbb30d8cb2695"), 
                    "topic" : "array", 
                     "name" : "array is best", 
                    "url" : "www.arr.com", 
                       "listname" : "dsa", 
                     "__v" : 0 }, 
               { "solved" : false,  
                 "_id" : ObjectId("60f2cc1b275bbb30d8cb269d"), 
                "topic" : "linked list",
               "name" : "reverse list", 
                 "url" : "www.list.com",
                "listname" : "dsa",
                 "__v" : 0 } 
               ], 
"__v" : 2 
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

you can use the following in your case

db.<collection_name>.updateOne(
    {   "_id" : ObjectId("60f2cc07275bbb30d8cb268e")},
    {
      $set: {
        'questionSet.$[].listname': "javascript"
      }
    } 
  )
over 4 years ago · Santiago Trujillo Relatório
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