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

246
Views
How to assign a value to a key within an array?

I am trying to add the about, link values into the description array defined in the schema and then use the .save() function to save it to the database. Any help would be appreciated. Thank You.

router.post('/:name/description',async(req, res)=>{
    const project = await Project.findOne({name: req.params.name})

    if (!project) {
        return res.status(404).send('project doesn\'t exist. Check URL');
    } else { 
        const {about, link} = req.body.description;
        console.log(project);
    }
});

Schema:

const projectSchema  = new mongoose.Schema({
    name: {
        type: String,
        required: true,
        unique: true
    },
    main_image: {
        type: Buffer
    },
    description:[{ 
        about: {
            type: String
        },
        github_link: {
            type: String
        }
    }]
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try using push:

router.post('/:name/description',async(req, res)=>{
    const project = await Project.findOne({name: req.params.name})

    if (!project) {
        return res.status(404).send('project doesn\'t exist. Check URL');
    } else { 
        const {about, link} = req.body.description;
        project.description.push({ about, github_link: link });
        await project.save();
        return res.status(201).send('Description added to project');
    }
});
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!