从mongoose数据库创建一个对象数组

时间:2014-09-29 21:56:35

标签: javascript mongodb mongoose

我在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?
  };
});

1 个答案:

答案 0 :(得分:0)

使用此代码

 var namesArray=[];
Users.find({ zip: '55555' }, function ( err, people ) {
  for ( i in people) {
    namesArray[i] = people[i]
  };
});