我正在尝试制作一个 Cutomer CLI 模型,但当我运行以下命令时,它给了我一个错误:
node commands.js add John Doe 555-555-5555 [email protected]
我一次又一次收到的错误是:
C:\Users\mrmik\Desktop\code\PROJECTS\Customer CLI\node_modules\mongodb\lib\connection_string.js:272
throw new error_1.MongoParseError(`${optionWord} ${Array.from(unsupportedOptions).join(', ')} ${isOrAre} not supported`);
^
MongoParseError: option usemongoclient is not supported
at parseOptions (C:\Users\mrmik\Desktop\code\PROJECTS\Customer CLI\node_modules\mongodb\lib\connection_string.js:272:15)
at new MongoClient (C:\Users\mrmik\Desktop\code\PROJECTS\Customer CLI\node_modules\mongodb\lib\mongo_client.js:48:63)
at _createMongoClient (C:\Users\mrmik\Desktop\code\PROJECTS\Customer CLI\node_modules\mongoose\lib\connection.js:887:14)
at NativeConnection.openUri (C:\Users\mrmik\Desktop\code\PROJECTS\Customer CLI\node_modules\mongoose\lib\connection.js:742:29)
at Mongoose.connect (C:\Users\mrmik\Desktop\code\PROJECTS\Customer CLI\node_modules\mongoose\lib\index.js:406:15)
at Object.<anonymous> (C:\Users\mrmik\Desktop\code\PROJECTS\Customer CLI\index.js:6:21)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12) {
[Symbol(errorLabels)]: Set(0) {}
}
我尝试的代码位于名为 commands.js 的文件中。 代码是:
const program = require('commander');
const{
addCustomer,
findCustomer
} = require('./index');
program
.version('1.0.0')
.description('Client Management System')
program
.command('add <firstname> <lastname> <phone> <email>')
.alias('a')
.description('Add a customer')
.action((firstname, lastname, phone, email) => {
addCustomer({firstname, lastname, phone, email});
});
program
.command('find <name>')
.alias('f')
.description('Find a customer')
.action(name => findCustomer(name));
program.parse(process.argv);
对我来说,这个错误只有在删除第二个可选变量后才停止:
{useMongoClient: true}
来自 2018 年一些旧教程建议的电话:
mongoose.connect();
在你的错误中我读到: “位于 Mongoose.connect (C:\Users\mrmik\Deskto