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

148
Views
How do I remove/delete project from project array?

I'm trying to delete a project object from an array.

projects:

  {
      _id : ...,
      userName: milad ,
      projets : [
        { .. projectId, pName, location .... A },
        { .. projectId, pName, location .... B },
        { .. projectId, pName, location .... C },
      ]
    }

How to delete Project B in MongoDB?

projects after remove Project B:

{
  _id : ...,
  userName: milad ,
  projets : [
    { .. projectId, pName, location .... A },
    { .. projectId, pName, location .... C },
  ]
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

If you have received a document from your database, you can remove an object from your array - based on the location - in such a way:

const doc = {
  _id: '507f191e810c19729de860e0',
  userName: 'milad',
  projects: [
    { _id: '507f191e810c19729de860ea', pName: 'projectA', location: 'a' },
    { _id: '507f191e810c19729de860eb', pName: 'projectB', location: 'b' },
    { _id: '507f191e810c19729de860ec', pName: 'projectC', location: 'c' }
  ]
}

// remove project b (one method, there are many more)
doc.projects = doc.projects.filter((project) => project.location !== 'b');

After the filter process you have to save it back to your mongoDB:

Mongoose: (example)

await doc.save();
about 4 years ago · Juan Pablo Isaza Report

0

another answer

db.collection('Profile').updateOne({ userName: username,
      "Projects.projectId": projectId }, { $pull: { 'Projects': { projectId: projectId } }})
  }
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!