我在mongodb / mongoose数据库中有一些用户,我想将他们所有人的姓名放在同一个邮政编码中。
var namesArray = [];
Users.find({ zip: '55555' }, function ( err, people ) {
for ( i = 0, i < people.length, i++ ) {
namesArray[i] = people.name // How do I specify which person to use if they're all being returned at once?
};
});
答案 0 :(得分:0)
使用此代码
var namesArray=[];
Users.find({ zip: '55555' }, function ( err, people ) {
for ( i in people) {
namesArray[i] = people[i]
};
});