express async get请求,调用async函数挂了

Express async get request, calling async function hanging

你好我是新来的快递...

我有一个快递文件,如:

const app = express();
const getPerson = require("./db/queries/PersonQuery");

app.get('/getCitizen/:id', async (req, res) => {
    try {
        const person = await getPerson.getCitizenById(`${req.params.id}`);
        console.log(person);
        res.send(person);
    } catch (e) {
        console.log(e);
    }
});

app.listen(3000);

我调用的函数如下所示:

const getCitizenById = async (id) => {
    try {
        const citizen = await CitizenSchema.find({
            citizenID : id
        });

        const cit1 = citizen[0];
        console.log(cit1);

        return cit1;

    } catch (e) {
        console.log(e);
    }
}

module.exports = { getCitizenById };

当我打电话时:http://localhost:3000/getCitizen/123 在邮递员上,我的请求只是挂起并且 returns 什么都没有,除了连接到数据库之外什么都不打印。

任何人都可以帮我吗?

非常感谢

编辑:

公民架构:

const mongoose = require ('mongoose');
const Schema = mongoose.Schema;

const citizenSchema = new Schema({
    citizenID : String,
    forenames : String,
    surname : String,
    homeAddress : String,
    dateOfBirth : String,
    placeOfBirth : String,
    sex : String
}, 
    { 
        collection : 'citizen10k'
    });

module.exports = mongoose.model('citizen10k', citizenSchema);

所以我重写了我的代码,我将 getCitizenId 函数嵌入到一个新函数中,该函数 运行 作为中间件,我包含了 next()。

现在有效。