简体   繁体   English

Express ( node.js ) - 类型错误:无法读取 null 的属性

[英]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.

相关问题 Node.js 显示类型错误:无法读取未定义的属性 - Node.js showing TypeError: Cannot read properties of undefined MongoDB Node.js TypeError:无法读取 null 的属性“db” - MongoDB Node.js TypeError: Cannot read property 'db' of null 未捕获的TypeError:无法读取null Node.js的属性&#39;getContext&#39; - Uncaught TypeError: Cannot read property 'getContext' of null Node.js node.js/express.js 连接池无法读取未定义的属性(读取“getConnection”) - node.js/express.js connection pool Cannot read properties of undefined (reading 'getConnection') Node.JS / Express / Mongo:TypeError:无法读取未定义的属性“位置” - Node.JS/Express/Mongo: TypeError: Cannot read property 'location' of undefined node.js/discord.js:类型错误:无法读取 null 的属性“setPresence” - node.js/discord.js: TypeError: Cannot read property 'setPresence' of null Node.js passport.use() function: TypeError: Cannot read properties of undefined (reading 'use') - Node.js passport.use() function: TypeError: Cannot read properties of undefined (reading 'use') Node.JS IPFS 发送消息 TypeError: Cannot read properties of undefined (reading 'publish') - Node.JS IPFS sending message TypeError: Cannot read properties of undefined (reading 'publish') Node.js 在 Heroku 上部署失败:TypeError:无法读取 null 的属性“拆分” - Node.js deploy on Heroku fail : TypeError: Cannot read property 'split' of null 在 Node.js 中导出 ZCCADCDEDB567ABAE643E15DCF0974E503Z 方法(类型错误:无法读取 null 的属性“名称”) - Exporting Mongoose methods in Node.js (TypeError: Cannot read property 'name' of null)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM