Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8032953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:32:39+00:00 2026-06-05T01:32:39+00:00

In my image sharing application you can upload images and create albums. When you

  • 0

In my image sharing application you can upload images and create albums. When you delete an image from the site it shall also be deleted in the albums (the ones that has got the image in it).

Below is the route for deleting an image, and what I really need help with is why the code for deleting the images (imageName and imageId) in the albums below doesn’t work.

Thanks in advance!

The models:

var AlbumSchema = new Schema({
      title             : String,
      imageName         : [String],
      imageId           : [String]
});

modelObject.AlbumSchema = AlbumSchema;
modelObject.Album = mongoose.model('Album', AlbumSchema);

–

var BlogPostSchema = new Schema({
    name : String,
    size : Number,
    type : String,
    author : ObjectId,
    title   : String
});

modelObject.Comment = mongoose.model('Comment', CommentSchema);
modelObject.BlogPost = mongoose.model('BlogPost', BlogPostSchema);

The part that doesn’t work in the code below is the following:

albums[i].imageName.remove(j);
albums[i].imageId.remove(j);                            
albums[i].save(function (err){
    if (err) {
        console.log(err);
        // do something
    }
});

Full code:

 app.get('/blog/delete/:id', function(req, res){

    model.BlogPost.findById(req.params.id, function (err, blog){

        var theImage = blog.name;

        var query = albumModel.Album.find( { imageName:theImage } )
        query.exec(function (err, albums) {

            if (!albums) {

                blog.remove(function(err) {
                    console.log(err);
                    // do something
                });

                res.redirect('/blogs');

            }

            else {
                for (var i = 0; i < albums.length; i++) {
                    for (var j = 0; j< albums[i].imageName.length; j++){

                        if (theImage == albums[i].imageName[j]){

                            albums[i].imageName.remove(j);
                            albums[i].imageId.remove(j);                            
                            albums[i].save(function (err){
                                if (err) {
                                    console.log(err);
                                    // do something
                                }
                            });
                        }
                    }
                }
            }

            blog.remove(function(err) {
                console.log(err);
                // do something
            });

            res.redirect('/blogs');
        });
    });
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:32:40+00:00Added an answer on June 5, 2026 at 1:32 am

    JavaScript arrays don’t have a remove method so I would expect your code may be crashing. You should be using code like albums[i].imageName.splice(j, 1); instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sharing an image from my application by starting Intent.ACTION_SEND with image msg.setType(image/png) using
Please recommend an image sharing service that can be called programmatically to upload a
I am building an advanced image sharing web application. As you may expect, users
I'm building a image sharing site and would like to know the pros and
Im working on an image sharing site and want to implement tagging for the
How can I change the name and the image that appear when sharing blog
I am working on Text Sharing on From my Android Application . I have
Can you please suggest me the efficient encoding technique to transfer image from iphone/android
how can I launch programmatically an application from a Windows shortcut (.lnk file)? I
For learning iOS programming I'm developing an iPhone application for sharing images. The application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.