Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!