Encountered an error in the terminal or command prompt as discussed below:
The specific error message is:
const taskCollection = db.collection('tasks');
^
TypeError: Cannot read properties of undefined (reading 'collection')
at Command.<anonymous> (C:\Abc\xyz\Task-Manager-CLI-Project\index.js:50:31)
at Command.listener [as _actionHandler] (C:\Abc\xyz\Task-Manager-CLI-Project\node_modules\commander\lib\command.js:494:17)
...
This pertains to a task manager CLI project linked with mongoDB, yet the persistent error remains unresolved. It's unclear where the issue lies. How can this be rectified? Below are snippets from two code files:
db.js
...
module.exports = {connect, getDB};
index.js
...
program.parse(process.argv);
Attempted altering the URI in MongoDB compass and changed it from "New Connection" to "Project1", updated the URI in db.js. No success.
Switched the URI from mongodb://localhost:27017 to mongodb://localhost:27018 or modified it to mongodb://localhost:27017/Project1. Still facing the same error.
The desired outcome is for commands list, add, delete to operate correctly in the command prompt based on the coded logic. However, the system reports that the collection tasks within database task_manager_db is undefined, leading to property-read errors.