mongodb文档中的附加id字段

时间:2018-05-10 16:19:44

标签: node.js mongodb express

我正在处理一个应用程序。问题是当我使用邮递员查看存储在mongodb中的裁剪文档时,还会出现一个额外的id字段,它与mongodb的_id字段相同。这是 id ,我知道mongodb提供的正常 _id 字段。

我有一个裁剪架构如下

const mongoose = require('mongoose');
const Pesticide = require('./Pesticide');
mongoose.Promise = global.Promise;
const Schema = mongoose.Schema;
const cropSchema = new mongoose.Schema({
nameOfCrop:{
  type:String,
  lowercase:true,
  required:'Please enter the name of the crop',
  trim:true
},
imageOfCrop:String,
soilType: String,
waterNeeded:String,
tagCrop:String,//forage, vegetable, oilseeds etc.
pesticideForCrop:[{
    type:mongoose.Schema.Types.ObjectId,
    ref:'Pesticide'
  }
]},
 {
toJSON: { virtuals: true },
toObject: { virtuals: true },
});

邮递员返回的实际文件是

{
"pesticideForCrop": [],
    "_id": "5af1d1d54558fae1d0010bb4",
    "nameOfCrop": "Tomato",
    "imageOfCrop": "tomatoimage",
    "soilType": " almost all soil types except heavy clay",
    "waterNeeded": "water once every two or three days",
    "tagCrop": "Vegetables",
    "id": "5af1d1d54558fae1d0010bb4"
}

我的方法如下所示:

exports.getCrops = function(req,res){
 Crop.find({}).populate('pesticideForCrop').exec(function (err, crops) {
 if (err) return err;
 res.send(crops);
 console.log(crops);
 });
 };

0 个答案:

没有答案
相关问题