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

122
Visualizações
Remove element in array by its index - mongoose

I have a mongoose model that looks like this:

 Member: {
  memberId: {
    type: String,
    required: true
  },
  customPlaylists: {
    type: Array,
    default: []
  }
       
         }

customPlaylist's array holds object that look like this:

{ name: 'playlist name', urls: [] } // urls array contains url strings

Is there a way using mongoose's updateOne method to remove a url from the urls array by its index in the array? (I use the member's ID in the filter object)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'm not sure if there is a straight (1 query) way to do this. But you can try this

<collectionName>.update({}, {$unset : {"urls.<indexNumberHere>" : 1 }}) 
<collectionName>.update({}, {$pull : {"urls" : null}})

There was a ticket to implement this feature and the resolution was Won't Do

about 4 years ago · Juan Pablo Isaza 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