-1

I am using Firebase Firestore to make my website

enter image description here

As you can see, I have a field commentList and its type is array and now I want to remove the first item of the array This is what I did:

exports.delete__comment = (req, res, next) => {
  const {id} = req.params;
  const {comment} = req.body;

  return db
    .collection('instagram__posts')
    .doc(id)
    .update({
      commentList: FieldValue.arrayRemove(JSON.stringify(comment)),
    })
    .then((doc) => {
      console.log('comment deleted', comment);
      next();
    })
    .catch((err) => {
      res.status(500).json({err});
      console.log(err);
    });
};

if the item was deleted, I will console.log('comment deleted', comment); and it worked

enter image description here

but the sad thing is it does not remove in the database for me instead, it still there. Please show me how to fix it, thank you so much and Merry Chirstmas

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

1

I am not sure why you converted comment object to string using JSON.stringify.

Try to use comment instead of JSON.stringify(comment).

michael
  • 4,053
  • 2
  • 12
  • 31