在MongoDB中需要执行push操作不起作用
我有一些他们正在查看,编辑,删除,添加每个网页的行动。
var roleprivilege = { 'role_name' : req.body.role_name, 'add':req.body['add'], 'del':req.body['del'], 'view':req.body['view'], 'edit':req.body['edit'], }
我正在使用findOneAndUpdate
mongo.role.findOneAndUpdate({'_id': id},roleprivilege,{upsert: true,new : true},function(err, response) { console.log("Inserted"); });
它的工作很好,但我需要存储所有添加,删除,编辑,查看里面的angular色。 我试过这样
var roleprivilege = { 'role_name' : req.body.role_name, 'role':{ 'add':req.body['add'], 'del':req.body['del'], 'view':req.body['view'], 'edit':req.body['edit'] } }
这里的问题是,如果我只select一个值的行为,它就像一个string存储
我的观点在这里
<div class="col-md-12 role_class" ng-repeat="menu in privilege_menu" > <div class="col-md-2">{{menu}}</div> <div class="col-md-10" ng-int="{{l_name =( menu|lowercase)}}"> <span class="role_checkbox"> <label class="control control--checkbox">View <input type="checkbox" ng-checked="check_role(l_name,'view')" name="view" value="{{menu|lowercase}}" /> <div class="control__indicator"></div> </label></span> <span class="role_checkbox" > <label class="control control--checkbox">Add <input type="checkbox" name="add" value="{{menu|lowercase}}" /> <div class="control__indicator"></div> </label></span> <span class="role_checkbox"> <label class="control control--checkbox">Edit <input type="checkbox" name="edit" value="{{menu|lowercase}}" /> <div class="control__indicator"></div> </label></span> <span class="role_checkbox"> <label class="control control--checkbox">Delete <input type="checkbox" name="del" value="{{menu|lowercase}}" /> <div class="control__indicator"></div> </label></span> </div> </div>
我需要以下格式的输出
{ "_id" : ObjectId("592817d6f6d6dd35c381bb0d"), "role_name" : "TSE", "role" : { "view" : [ "dashboard", "settings", "users", ], "add" : [ "vehicles", "customers", "reports" ], "edit" : [ "users" ] } }
我的req.body看起来像这样
{ role_name: 'SA', view: [ 'dashboard', 'users', 'settings' ], add: 'users', edit: 'users', del: [ 'users', 'settings' ] }
这里的问题是,当只有一个元素时,req.body不使用列表对象,例如:
view: [ 'dashboard', 'users', 'settings' ], add: 'users', instead of add: ['users']
在将其插入到mongoDB中之前,您需要改进创buildvariablesrolePrivilege来处理这种情况。
当您打印时,您希望roleprivilege看起来像这样:
{ 'role_name' :'SA', 'role':{ 'add': ['users'], 'del': [ 'users', 'settings' ], 'view':[ 'dashboard', 'users', 'settings' ], 'edit':['users'] } }
- Angular4应用程序,npm安装给'$不被识别为内部或外部命令'的错误
- Angular / Express:redirect到login后访问的最后一页
- 量angular器:在一个js中初始化全局variables,并在其他js中使用相同的variables
- 使用angular2 +服务编辑对象,mongoDB和NodeJs
- Webpack错误:TypeError:对象原型可能只是一个Object或null:undefined
- 为什么我的NodeJS量angular器在Travis CI上testing失败并出现错误
- Angular2与TypeScript:声明预期编译器错误@component后
- 使用ElementArrayFinder.filter()和async / await
- Angular 2的http请求在新系统上处于挂起/取消状态