node.js - How to insert data from HTML page as sub documents in mongoDB in Mean-stack application -
i trying insert data sub document in meanstack application. below schema:
var employee = mongoose.model('employee', mongoose.schema({ weekstart : { type:date, default: date.now}, weekend : { type:date, default: date.now}, // user : [{ type: schema.types.objectid, ref: 'employee' }], timesheet:[{ project:{ type:string}, activity:{ type:string}, day:{type: string}, hours:{type: number} }] }));
in above, want insert data html page activity, project, day , hours.
the api return purpose is:
app.post('/api/employees', function(req, res){ employee.create( req.body, function(err, employees,time){ if(err) return res.send(err); res.json(employees); console.log(employees); console.log(time); }); });
the service is:
$scope.addtimesheet = function(data){ $scope.time = []; //var id = $routeparams.id; $http.post('/api/employees/', $scope.employee).then(function(response){ $scope.employee = response.data; $http.get('/api/employees/' ).success(function(response){ $scope.time = response.timesheet; window.location.href = '/'; }); }); }
the html page is:
<tbody> <tr id="tablerow"> <td> <select name="project stream" ng-model="time.timesheet.project"> <option value="">project stream</option> <option value="drones">drones</option> <option value="virtual reality">virtual reality</option> <option value="augmented reality">augmented reality</option> <option value="arch – automation">arch – automation</option> <option value="arch – devops">arch – devops</option> <option value="voice">voice</option> </select> </td> <td> <select name="activities" ng-model="time.timesheet.activity"> <option value="">activities</option> <option value="research">research</option> <option value="development">development</option> <option value="test/deploy">test/deploy</option> <option value="demo">demo</option> </select> </td> <td> <select name="week" ng-model="time.timesheet.day"> <option value="">week</option> <option value='monday'>monday</option> <option value='tuesday'>tuesday</option> <option value='wednesday'>wednesday</option> <option value='thursday'>thursday</option> <option value='friday'>friday</option> <option value='saturday'>saturday</option> </select> </td> <td> <center><input type = "number" min="0.5" max="9" style="width: 55px" required ng-model="$parent.time.timesheet.hours"></center> </td> <!-- <td><center><input type = "number" min="0.5" max="9" style="width: 55px" required ></center></td> <td><center><input type = "number" min="0.5" max="9" style="width: 55px" required ></center></td> <td><center><input type = "number" min="0.5" max="9" style="width: 55px" required ></center></td> <td><center><input type = "number" min="0.5" max="9" style="width: 55px" required ></center></td> <td><center><input type = "number" min="0.5" max="9" style="width: 55px" required ></center> </td> --> </tr> <tr> <td> <center><input type = "text" ></center> </td> <td> <center><input type = "text" ></center> </td> <td> <center><input type = "text" ></center> </td> <td> <center><input type = "text" style="width: 55px" required ></center> </td> <!-- <td><center><input type = "text" style="width: 55px" required ></center></td> <td><center><input type = "text" style="width: 55px" required ></center></td> <td><center><input type = "text" style="width: 55px" required ></center></td> <td><center><input type = "text" style="width: 55px" required ></center> </td> --> </tr> </tbody>
Comments
Post a Comment