Wednesday, 5 April 2017

Update data in mongoDB with Moongoose and MEAN Stack

Hi i have a mongoose data like this

{
    "_id" : ObjectId("58e394cacaa6512ed00e8d83"),
    "RoleName" : "Manager",
    "UIList" : [ 
        {
            "Edit" : false,
            "View" : false,
            "UiName" : "ElevatorMapping"
        }, 
        {
            "Edit" : false,
            "View" : false,
            "UiName" : "ElevatorAssumptions"
        }, 
        {
            "Edit" : false,
            "View" : false,
            "UiName" : "ManageUnits"
        }, 
        {
            "Edit" : false,
            "View" : false,
            "UiName" : "ManageBuildings"
        }
    ],
    "__v" : 0,
    "Description" : "fd",
    "IsActive" : true
}

Now I want to update UILIST inside all the View and Edit as True How to write query for this. I have tried something like below.

Here is my Controller page.

$scope.UIUpdateTable = function () {

    debugger;

 for (var i = 0; i < $scope.Manage_RolesUIshow.length; i++) {
        debugger;
        var id = $scope.Manage_RolesUIshow[i]._id;
        var uiname = $scope.Manage_RolesUIshow[i].UiName;
        var view = $scope.Manage_RolesUIshow[i].View;
        var edit = $scope.Manage_RolesUIshow[i].Edit;

        $http.put('/ViewEditupdate/'+uiname +'/'+ view + '/' + edit).then(function (response) {
            console.log(response);
            refresh();
        })
    }
};

here id value is taken correctly but the Edit view UI names are not taken. Edit , view name taken as undefined.

my server.js code

app.put('/ViewEditupdate/:uiname/:view/:edit', RoleEntrypath.RoleViewEditupdate);

here is my html page

 <tbody>
                                                                <tr dir-paginate=" Manage_Rolesui in Manage_RolesUIshow[0].UIList | itemsPerPage:15 | orderBy:orderByField:reverseSort " pagination-id="paginate1" ng-class-odd="'odd'">
                                                                    <td ng-click="profileform.$show()">
                                                                        <span e-ng-change="applyHighlight($data)">
                                                                            
                                                                        </span>
                                                                    </td>
                                                                    <td ng-click="profileform.$show()" align="center">
                                                                        <div>
                                                                            <span e-ng-change="applyHighlight($data)"
                                                                                  editable-checkbox="Manage_Rolesui.View" e-form="rowform" ng-click="profileform.$show();">
                                                                                <input type="checkbox" ng-model="Manage_Rolesui.View" width="20" />
                                                                            </span>
                                                                        </div>
                                                                    </td>
                                                                    <td ng-click="profileform.$show()" align="center">
                                                                        <span e-ng-change="applyHighlight($data)" ng-checked="Manage_Rolesui.Edit"
                                                                              editable-checkbox="Manage_Rolesui.Edit" e-form="rowform" ng-click="profileform.$show()">
                                                                            <input type="checkbox" ng-model="Manage_Rolesui.Edit" width="20" />
                                                                        </span>
                                                                    </td>

                                                            </tbody>

my Schema code

exports.RoleViewEditupdate = (req, res) => {
    debugger;
    var id = req.params.id;
    var UIName = req.params.UiName;
    var VIEW = req.params.View;
    var EDIT = req.params.Edit;
    newRole.update({ _id: id }, { $set: { "UIList.$": {  UiName: UIName, View: VIEW, Edit: EDIT } } },
       function (err, doc) {
           if (err) {
               console.log('error occured');
           }
           else {

               return res.send(204);
           }
       }
   );
};

can any one give the solution.



via Vinoth

No comments:

Post a Comment