如何获取mongodb对象数组中的特定字段

问题描述 投票:0回答:1

enter image description here

在上面的显示图中我只需要每个对象的路径。我试过这样的事

userRouter.post('/delete_products',function(req,res){
Collections.product.find({ "_id": req.body.id }, { "pimages.path": "1" },function(err,result){
    if(err)
    res.send(err)
    else
    res.send(result)
    const map=result.map(user=>user.pimages.map(user=>user.path))
    console.log(map);
})

})

[ [ '1552640783_mixer front.jpg', '1552640783_mixer back.jpg' ] ]

我是这样的。我希望以对象形式的数组输出

[{'1552640783_mixer front.jpg'},{......}]

提前致谢。

node.js mongodb
1个回答
0
投票

在Object中,值被写为name:value对。例如:

{
name : "M-DIT KOZHIKODE",
location : "Kerala",
established : 2012
}

我没有得到你期望的结果背后的逻辑。

© www.soinside.com 2019 - 2024. All rights reserved.