node.js - 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
}]
解决方案
You can use the following solution to solve your problem:
{ $pullAll: { roleAssigned: ['user'] } };
推荐阅读
- javascript - 在javascript中使用查询选择器
- javascript - 反应钩子数组特定问题的结构
- r - R中的POST请求:带有xml的upload_file()中的错误
- angular - Angular ngOnInit 如何将订阅结果用于另一个订阅/后端调用?
- java - 如何检测 3d 空间中 2 个三角形之间的碰撞?
- bash - 如何搜索可能跨越也可能不跨越两行的字符串?
- haskell - Haskell 中有任意大的数据结构吗?
- javascript - 使用按钮调用 API 并将结果返回给回调函数
- python - 使用 django bootstrap 组件时,Django plotly dash-application 返回完全空白页面
- reactjs - 在 Material UI 和条件渲染中接收道具