发布到MongoDB返回空数组

时间:2016-01-06 15:12:20

标签: javascript node.js mongodb mean-stack

我在将数据发布到我的mongo数据库时遇到了麻烦。它适用于StudentTable,但不适用于CourseTable,即使代码看起来相同。我注意到data返回的是空数组,如下图所示(控制台输出)

我搜索的时间很长很难,但我找不到任何问题来帮助我。

app.js

o.create = function (student) {
    console.log("Studenttest");
    console.log(student);
    return $http.post('/students', student)
        .success(function (data) {
            console.log(data);
            o.students.push(data);
        });
};

o.create = function (course) {
    console.log("Coursetest");
    console.log("course");
    console.log(course);
    return $http.post('/courses', course)
        .success(function (data) {
            console.log("data");
            console.log(data);
            o.courses.push(data);
        });
};

控制台输出 enter image description here

编辑: 按照要求,这是我的模型

Students.js



var mongoose = require('mongoose');

var StudentSchema = new mongoose.Schema({
  sID: { type: Number, min: 400000, max: 500000 },
  csCourses: [String],
  Courses: [String]
  });


mongoose.model('StudentTable', StudentSchema);




Courses.js



var mongoose = require('mongoose');

var CourseSchema = new mongoose.Schema({
  courseID: [String],
  courseTimes: [String]
  });


mongoose.model('CourseTable', CourseSchema);




0 个答案:

没有答案