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

143
Views
Why does setting the property as a constant work in mongo mongoose but not just the method getting the value

I am trying to update some value in my database using python and mongoose (mongo wrapper library). The value I am trying to update is contained in an array (filename).

Full method

module.exports.updateCampground = async (req, res) => {
    const { id } = req.params;
    const campground = await Campground.findByIdAndUpdate(id, { ...req.body.campground });
    const imgs = req.files.map(f => ({ url: f.path, filename: f.filename }));
    campground.images.push(...imgs);
    await campground.save();
    if (req.body.deleteImages) {
        for (let filename of req.body.deleteImages) {
            //logs cloudinary conataining uploader, still uploader is undefined
            console.log(cloudinary,cloudinary.uploader); 
            await cloudinary.uploader.destroy(filename);
        }
        await campground.updateOne({ $pull: { images: { filename: { $in: req.body.deleteImages } } } })
    }
    req.flash('success', 'Successfully updated campground!');
    res.redirect(`/campgrounds/${campground._id}`)
};

This works

const deleteImg = req.body.deleteImages
await campground.updateOne({ $pull: { images: { filename: { $in: deleteImg } } } })

and removes the item however when I do just this it doesn't

await campground.updateOne({ $pull: { images: { filename: { $in: req.body.deleteImages } } } })

Why do I need the const to work? Is it some javascript thing?

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