在这里,我想清楚地解释我的问题
我需要使用子文档ID更新子文档数组,而不需要获取父ID
这是我的路线
router.get('/register-list', function(req, res){
RegisterList.find(function(err, docs){
res.json(docs);
});
});
这里是使用nodejs从registerList获取数据。
使用上面的路由代码,这里使用下面的angularjs控制器代码获取子文档数组数据,并使用ng-repeat显示它。
这是我的angularjs控制器代码
$scope.RegisterView = function(id){
$http.get('/auth/register-list/' + id).success(function(response){
$scope.bookinglist = response.booking;
});
};
HTML视图
<tr ng-repeat="booking in bookinglist">
<td>{{booking.order_id}}</td>
<td>{{booking.can_name}}</td>
<td>{{booking.can_quantity}}</td>
<td>{{booking.can_cost}}</td>
<td>{{booking.delivery_date}}</td>
<td>{{booking.delivery_timeslot}}</td>
<td>{{booking.subscription_type}}</td>
<td><button type="button" class="btn btn-primary" ng-click="RegisterEdit(booking._id)">Edit</button>
</td>
<td>
<button type="button" ng-click="RegisterUpdate(booking._id)" class="btn btn-success">Update</button>
</td>
</tr>
Json查看:
Mongoose Schema:
var mongoose = require('mongoose');
var registerSchema = mongoose.Schema({
area_name : String,
warehouse_name : String,
booking : [{
order_id : String,
can_name : String,
can_quantity : String,
can_cost : String,
delivery_date : Date,
delivery_timeslot : String,
subscription : String,
subscription_type : String,
total_cost : String,
status: { type: String, default: 'UnderProcess' },
ordered_at: { type: Date, default: Date.now },
delivered_at: { type: Date }
}],
name: String,
email : String,
mobile_no : String,
password : String,
otp : String,
address : [{
flat_no: String,
street: String,
city: String,
}],
date: { type: Date, default: Date.now }
});
module.exports = mongoose.model('RegisterList', registerSchema);
帮助找出子文档使用subdocument_id并使用子文档ID更新父文件ID