我是nodejs和mongoose的初学者。我正在尝试检索 astname 拥有笔记本电脑的类别值。请建议我如何实现这一目标。
var astname = "Laptop";
Asset.find({ astname : astname}, function(err, foundcategory){
if(err){
console.log(err);
} else {
console.log(foundcategory.category);
}
})
最佳答案
foundcategory
在您的示例中是一个数组。使用 findOne
而不是 find
来查询单个文档。
var astname = "Laptop";
Asset.findOne({ astname : astname}, function(err, foundcategory){
if(err){
console.log(err);
} else {
console.log(foundcategory.category);
}
})
关于node.js - 如何从 Mongoose 查询中检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51211604/