[英]Express ( node.js ) - TypeError: Cannot read properties of null
I use Express ( node.js ) and MongoDB. When I try to view or update user profile I get an error我使用 Express ( node.js ) 和 MongoDB。当我尝试查看或更新用户配置文件时出现错误
middleware token check worked
getProfileFields:::::::::::::>>>>e: TypeError: Cannot read properties of null (reading 'minAge')
at module.getProfileFields (C:\localhost\website\app\controllers\api\profile.js:34:22)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
it seems problem with this part of code这部分代码似乎有问题
module.getProfileFields = async (req, res) => {
var successMessage = { status: 'success', message:"", data:{}};
var failedMessage = { status: 'fail', message:"", data:{}};
try {
var profileFields = await model.ProfileFields.find({isDeleted:false},{slug:1, options:1,type: 1});
var obj = {
...
educationLevel: [],
hobbies: [],
whatYouSay: [],
minAge: settings.minAge ? settings.minAge : 0,
maxAge: settings.maxAge ? settings.maxAge : 0,
religion: []
};
}
successMessage.message = "Successfully loaded profile reference";
successMessage.data = obj;
res.send(successMessage);
} catch (e) {
console.log('getProfileFields:::::::::::::>>>>e: ',e);
failedMessage.message = "Something went wrong";
res.send(failedMessage);
}
}
How to solve this problem?如何解决这个问题呢?
Settings are empty, maybe they are not exported correctly.设置为空,可能没有正确导出。 Check your settings file.检查您的设置文件。
I think you're not using the find API call for MongoDB properly, find usually takes up a filter object and an object of properties as a second argument.我认为您没有正确使用 find API 调用 MongoDB,find 通常占用过滤器 object 和属性 object 作为第二个参数。 Check the syntax required for find(){} function and probably you'll get through with it.检查 find(){} function 所需的语法,您可能会搞定。
Hope it helps.希望能帮助到你。 Happy coding!!编码快乐!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.