mongodb如何定义嵌套文档。
作为一个mongodb的初学者,我想实现一个mongodb的嵌套查询,接下来是我的代码,各位大神看看是哪里出了问题。
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
/*
Applicant Schema
*/
var interview = new Schema({
date: {
type: Date
},
interviewer: {
type: String
},
comment: {
type: String
}
});
var applicantschema = new Schema({
job: {
type: String,
required: true
},
name: {
type: String
},
gender: {
type: String
},
birth: {
type: Date
},
email: {
type: String
},
telephone: {
type: String
},
arrivalDate: {
type: Date
},
years: {
type: Number
},
wage: {
type: Number
},
remarks: {
type: String
},
result: {
type: String
},
interview: [interview]
});
module.exports = mongoose.model('applicant',applicantschema);
以上lib端的model文件,接下来就是app端的controller文件中的关于写入mongodb里面的部分代码。
$scope.applicant.name = $scope.name;
$scope.applicant.gender = $scope.gender;
$scope.applicant.birth = $scope.birth;
$scope.applicant.email = $scope.email;
$scope.applicant.telephone = $scope.telephone;
$scope.applicant.years = $scope.years;
$scope.applicant.wage = $scope.wage;
$scope.applicant.remarks = $scope.remarks;
$scope.applicant.job = $scope.job;
$scope.applicant.arrivalDate = $scope.arrivalDate;
//$scope.applicant.result = $scope.result;
$scope.applicant.interview.date = $scope.date;
$scope.applicant.interview.interviewer = $scope.interviewer;
$scope.applicant.interview.comment = $scope.comment;
console.log( $scope.applicant.interview.date + "&&&&&&&&&&&");
然后报错显示的是interview is undefined.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没做过这样的需求,帮你google了下。你看看对不对
http://stackoverflow.com/questions/18001478/referencing-another-schema-in-mongoose