Node.js 如何从mongoose中检索对象值
对象如下所示:Node.js 如何从mongoose中检索对象值,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,对象如下所示: { "_id" : ObjectId("5969b38a9ab0c60370a6dea3"), "name" : "789", "dec" : "789", "regular" : "789", "sale" : "78", "stock" : "8", "cat" : {
{
"_id" : ObjectId("5969b38a9ab0c60370a6dea3"),
"name" : "789",
"dec" : "789",
"regular" : "789",
"sale" : "78",
"stock" : "8",
"cat" : {
"wallets" : [{
"selected" : "true",
"subcategory" : "leather"
}]
},
"imgs" : [
"file-1500099465305.png",
"file-1500099465310.png"
],
"__v" : 0
}
我的问题是
如何通过查询检索mongodb中的特定值
导入您的模型并通过查询找到您的实例:
现在,当您调用此函数时,您将获取实体作为对象,并且可以从中获取实体对象键。欢迎使用堆栈溢出。请花点时间阅读
export function myFunc(req, res) {
return Model.find({ 'name.last': 'Ghost' }} //your condition
})
.then(entity=> {
if (entity) {
console.log(entity) // to see object
res.status(200).json({'entity': entity}).end();
} else {
return res.status(404).end();
}
}).catch(handleError(res)); // error handling
}