How mongodb defines nested documents.

  node.js, question

As a beginner of mongodb, I want to implement a nested query of mongodb. Next is my code. Let’s see what went wrong.

var mongoose = require('mongoose'),
 Schema = mongoose.Schema;
 
 
 /*
 Applicant Schema
 */
 var interview = new Schema({
 date: {
 type: Date
 },
 interviewer: {
 type: String
 },
 comment: {
 type: String
 bracket
 
 
 });
 
 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);

The above model file on lib side is followed by some codes written in mongodb in the controller file on app side.

$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.

I haven’t done such a demand, and I helped you google it. You see right

interview:{
 type: mongoose.Schema.Types.Object, ref: 'interview'
 bracket

http://stackoverflow.com/questions/18001478/referencing-another-schema-in-mongoose