Home > Blockchain >  I want delete one field that mi table but I dont want to make that
I want delete one field that mi table but I dont want to make that

Time:10-21

    db.users("user")
    .find()
    .forEach((elm) => {

        if(elm.name === 'john'){
            elm.pop();
        }else {
            print("Nothing to deleted")
        }
    });

The code said elm.pop() is not a function, I try with deleted, remove...any idea??

Thanks for all!

CodePudding user response:

I cant't understand what you are trying to do here ,
I hope this may work

if you want to return all the document which name is not equal to "john"

https://mongoplayground.net/p/sCNe6gnJLij

db.collection.find({
  name: {
    "$ne": "john"
  }
});

if you want delete the documents which contains name as "john" then use

db.collection.deleteMany({
  name: {
    "$ne": "john"
  }
});

  • Related