【发布时间】:2014-06-28 03:03:00
【问题描述】:
我是 node.js 和 mongodb 的新手,并且在下面的代码中,我在部门的表员工中定义了一个引用,但是当我从这里插入或获取数据时员工表我总是以数组格式获取,但我想将引用定义为单列而不是多列。
var employee = new mongoose.Schema({
name: String,
dept: [department]
});
var department = new mongoose.Schema({
dept_name : String,
dept_code : String
})
我想要来自员工表的响应数据,格式为 `{"name":"CS",dept:{"id":_id_of_dept}}
请指导我实现目标的正确方法。
【问题讨论】: