我使用 nodejs 和 mongodb。
我从以下 mongodb 查询中获取字典 res:
Profile.find(search,['_id', 'username'],function(err, res)
打印资源看起来像:
[
{
"username": "dan",
"_id": "508179a3753246cd0100000e"
},
{
"username": "mike",
"_id": "508317353d1b33aa0e000010"
}
]
}
我想向每个 res[x] 推送另一个键值对:
[
{
"username": "dan",
"_id": "508179a3753246cd0100000e",
"more info": {
"weight": "80",
"height": "175"
}
},
{
"username": "mike",
"_id": "508317353d1b33aa0e000010"
},
"more info": {
"weight": "80",
"height": "175"
}
]
}
我试过了 :
var x=0
dic = []
while (x<res.length){
dic[x] = {}
dic[x]=res[x]
dic[x]["more info"] = {"wight" : weight, "height" : hight}
x=x+1
}
但它被忽略了,我得到了
[
{
"username": "dan",
"_id": "508179a3753246cd0100000e"
},
{
"username": "mike",
"_id": "508317353d1b33aa0e000010"
}
]
}
感谢你的帮助。