node.js查询未返回结果,但在mongo shell中

时间:2019-05-02 20:52:50

标签: node.js mongodb

我的控制器中有一个函数可以提取一些数据:

Registration.aggregate([ 
  {$unwind:"$players"},    
  { $lookup: 
  { from: "waiverrecipients", localField: "players.email", foreignField: "email", as: "WAIVERS" } 
},
  {$unwind: "$WAIVERS"}
])
.exec(function(err, registrations) {
  console.log("PLAYERLIST",registrations, err);
if (err) {
  console.log("Error finding registrations", err);
  res.status(500).json(err);
} else {
  console.log("Found " + registrations.length + " registered PLAYERS");
  console.log(registrations);
  res.status(200).json(registrations);
}
});
};

当我在mongo shell中测试查询时,我从字面上复制并粘贴并使用集合名称而不是我的猫鼬“ Registration”引用:

db.registrations.aggregate([ {$unwind:"$players"},    { $lookup:              { from: "waiverrecipients", localField: "players.email", foreignField: "email", as: "WAIVERS" } },{$unwind: "$WAIVERS"} ])

结果出现在mongo shell中,但是当我尝试在AngularJS中运行它时,前端得到状态码200和一堆HTML。有人可以帮我弄清楚我在做什么错吗?

0 个答案:

没有答案