【发布时间】:2015-03-06 13:41:25
【问题描述】:
在我的 Mongoose 架构中,我有一个 id 字段,每个文档都有一个唯一的 ID。这与默认 _id 字段使用的系统相同,如下所示:
var JobSchema = new mongoose.Schema({
id: { type:String, required:true, unique:true, index:true, default:mongoose.Types.ObjectId },
title: { type: String },
brief: { type: String }
});
module.exports = mongoose.model("Job", JobSchema);
现在,如果我查询架构以获取 id 和标题,我会这样做:
Job.find().select("id title").exec(function(err, jobs) {
if (err) throw err;
res.send(jobs);
});
但是,我发现这会按预期返回 id 和 title,但它也返回默认的 _id 字段。为什么会这样?我该如何阻止它?
【问题讨论】:
标签: javascript json node.js mongodb mongoose