mongodb - Pushing inside multiple array's in Mongoose -
as new mongoose, able push inside single array using $push when tried $push multiple array fields no error shown on console database not updating recent values
model:
var networkschema = new schema({ userid: { type: schema.types.objectid, ref: 'user' }, networklist: [{ type: schema.types.objectid, ref: 'user' }], networkrequest: [{ to:[{ type: schema.types.objectid, ref: 'user'}], from:[{ type: schema.types.objectid, ref: 'user' }] }] });
page:
<div ng-controller="authenticationcontroller" style="margin-top: 50px"> <div ng-controller="networkscontroller"> <ul> <li ng-repeat="network in networkfriends"> {{network.firstname}} <button type="submit" class = "btn btn-default" data-ng-click="update(network._id,network.email)">add friend</button> </li> </ul> <button type="submit" ng-click="showlist()">show</button> </div> </div>
client controller:
$scope.update = function(friendid,mcreg) { var userid = this.authentication.user._id; var networklist = [friendid]; var networkrequest = [{ to:friendid }, { from: mcreg }]; console.log(json.stringify(networklist)); $http.post('/networks/update',{userid: userid,friendid: friendid, mcreg: mcreg, networkrequest: networkrequest, networklist: networklist}).success(function(response){ console.log('hello'); console.log(json.stringify(response)); });
here server controller:
exports.update = function(req, res) { var query={'userid':req.body.userid}; var update = {$push: {'networkrequest':{to: req.body.friendid, from: req.body.mcreg}, 'networklist': req.body.friendid}}; network.find(query,function(err,user){ console.log(user); if (err) { return err; } else { console.log('no error'); } }); network.update(update,function(err){ if (err) { return err; } else { console.log('updated'); } });
when console update variable ,value of networkrequest , networklist shown not inserted inside database.
Comments
Post a Comment