Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

delete single image by using user id in node js mongodb

// User delete his single image by using user id and image id
const deleteSingleImageByUserId = async (req, res) => {
  try {
    const user = await User.findByIdAndUpdate(
      req.params.userId,
      {
        $pull: {
          images: {
            _id: req.params.imageId,
          },
        },
      },
      { new: true }
    );

    //console.log("req params imageId: ", req.params.imageId + images);

    if (!user) {
      return res.status(400).send("User not found");
    }

    await Imageup.findByIdAndDelete(req.params.imageId);

    res.send("Image is deleted successfully!");
    console.log("user user: ", user);
  } catch (err) {
    res.status(500).send("Something went wrong!");
  }
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript expressions JSX 
Javascript :: react native on expo finger print is working bt not in apk 
Javascript :: liste des mois javascript 
Javascript :: excluding a attribute from json strigify 
Javascript :: how to clear screen in vis code 
Javascript :: formatar data com jquery 
Javascript :: jquery unobtrusive validation asp.net core 
Javascript :: node alternative to btoa 
Javascript :: ex:javascript array 
Javascript :: Transform raw text to links 
Javascript :: setimteout use function generator 
Javascript :: mutationobserver specific attribute 
Javascript :: bad site theme 
Javascript :: node command get to much time 
Javascript :: wordpress apostrophe problem in javascript 
Javascript :: measure width in px chrome extension 
Javascript :: george will turn g years old in year k 
Javascript :: how to put strings in console javascript 
Javascript :: moment add days non destructive 
Javascript :: help source code discord.js 
Javascript :: how to turn a page upside down in javascript 
Javascript :: how to calculate each row with on change table <td<input jquery 
Javascript :: puppeteer enable location permission 
Javascript :: dom-to-image bad quality 
Javascript :: store current date in chrome storage extension 
Javascript :: input search picture jquery 
Javascript :: how to convert json to bootstrap treeview format 
Javascript :: reverse a number in javascript without using inbuilt function 
Javascript :: time second updating without rendering 
Javascript :: install phantomjs Alpine Linux 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =