首页 > 解决方案 > unable to update the array using pull in node.js

问题描述

I wanted to delete 'user' entry from 'roleAssigned' array In the code:

Contact.update({ firstName:'Abhishek'},{$pull: { roleAssigned:'user'}});

This is what the Contact mongoDB model looks like:

[{
    roleAssigned: ['user', 'admin'],
    _id: 5b9b8ef904bc042c8f94f1fe,
    firstName: 'abhishek',
    lastName: 'soni',
    date: 2018-09-14T10:35:37.922Z,
    __v: 0
}]

标签: node.jsmongodbmongoose

解决方案


You can use the following solution to solve your problem:

{ $pullAll: { roleAssigned: ['user'] } };

推荐阅读