Home > Net >  How not to delete the whole document in mongoose (express.js), but just only a string in an array
How not to delete the whole document in mongoose (express.js), but just only a string in an array

Time:03-01

this is my first time on this platform and my english is bad so sorry if I don't understand all the intricacies of my problem.

I have question about: why does findOneAndDelete() in mongoose delete all document instead of deleting exat string of array.

Thats my mongoose document in my collection: thats document

what i need exatly is to remove the string[.1]-uk of array in my soketController (node.js/express.js/server) if thats string is the same with result value (its supposed to be same after convert). its server side i tried this or findOneAndDelete({name:result}) but is delete whole document or doesnt work at all ($pull).

Thanks in advance for your help

CodePudding user response:

I found out my issue.

$pull works with something else like $in

so:

const final = await AllUrlDb.updateOne(isDetleteURL,{
                                       $pull: {
                                          name:{
                                            $in: [result]
                                          }
                                       }
                                    })
  • Related