这是代码:
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
开头是req.params._id
我在寻找的usermodel.findOne
。我也收到此错误:
/Users/rodrie/Documents/node/node_modules/mongoose/lib/utils.js:434
throw err;
^
TypeError: Cannot read property '_id' of null