简体   繁体   English

MongoDB collection.find()查询挂起

[英]MongoDB collection.find() query hanging

I am trying to make a query to find a user by username like so: 我正在尝试进行查询以按用户名查找用户,如下所示:

userRouter.get('/user/:user_username', function(req, res) {
console.log("GET request to '/user/" + req.params.user_username + "'");

User.find({ usernmame: req.params.user_username }, function(err, user) {
  if (err) res.send(err); return;

  res.json(user);
});

}); });

The query never completes and Chrome dev tools is showing 'pending' on the request. 查询从未完成,Chrome开发人员工具在请求中显示“待处理”。 It's definitely going to that route because it prints the console message I logged at the start. 肯定要走那条路,因为它会打印出我一开始记录的控制台消息。 I executed the same query in the mongo cli and it works. 我在mongo cli中执行了相同的查询,并且有效。 I tried logging messages in the callback body, but it never gets to that point. 我尝试将消息记录在回调主体中,但是到那时为止。 I'm at a loss as to what to do at this point. 我现在不知所措。

It's because if (err) res.send(err); return; 这是因为if (err) res.send(err); return; if (err) res.send(err); return; gets evaluated as 被评估为

if (err) {
    res.send(err);
}

return;

To fix the issue, consider adding some braces. 要解决此问题,请考虑添加一些花括号。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 复杂的collection.find()查询并使用{{#each collection}}进行渲染 - Complex collection.find() query and render it using {{#each collection}} nodejs和MongoDB的collection.find()不响应 - nodejs and MongoDB's collection.find() does not respond mongodb:使用$ in运算符的collection.find不返回任何内容 - mongodb: collection.find with $in operator doesn't return anything 代码停滞在collection.find - Code stalling at collection.find 在nodejs collection.find()中没有从Mongodb集合中获取值,它什么也不返回 - In nodejs collection.find() is not fetching values from Mongodb collection.It returning nothing 如何访问mongodb collection.find方法返回的Expressjs中的特定字段? - How to access a specific field in Expressjs returned by mongodb collection.find method? node.js mongodb-collection.find()。toArray(callback)返回空 - node.js mongodb - collection.find().toArray(callback) returns empty node.js mongodb - collection.find()。toArray(callback) - 不调用callback - node.js mongodb - collection.find().toArray(callback) - callback doesn't get called 在快速app.js文件中使用mongodb的collection.find()时出现问题 - Issue with mongodb's collection.find() when used in an express app.js file Express 和 MongoDB,使用 $text 和 $search 时 collection.find 中出现转义字符的问题 - Express and MongoDB, problem with escape characters in the collection.find while using $text and $search
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM