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