1
數組裏面的_id這是代碼:搜索與貓鼬
usermodel.findOne({"imagen._id": req.params.id }, {imagen: 1}, function (err, imagen){
if(err) throw err;
console.log(req.params.id + '\n');
console.log(imagen);
res.send(imagen);
});
這是架構:
var userschema = new mongoose.Schema({
user: String,
imagen: [{
title: String,
name: String,
author: String,
}]
});
我想要得到這樣的輸出:
{ title: 'DQ monstes',
name: 'fooname.png',
author: 'fooauthor',
}
但是我得到這個:
{ _id: 50f41ccff405ef73c4000006,
imagen:
[ { title: 'Pokemon',
name: 'random.png',
author: 'fooauthor',
},
{ title: 'DQ monstes',
name: 'fooname.png',
author: 'fooauthor',
}
的_id
一開始是我在usermodel.findOne
尋找req.params._id
。我也收到這個錯誤:
/Users/rodrie/Documents/node/node_modules/mongoose/lib/utils.js:434
throw err;
^
TypeError: Cannot read property '_id' of null