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"
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"
}
});