Error:
C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongodb\lib\connection_string.js:281 throw new error_1.MongoParseError( ${optionWord} ${Array.from(unsupportedOptions).join(', ')} ${isOrAre} not supported
); ^
MongoParseError: options usecreateindex, usefindandmodify are not supported at Object.parseOptions (C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongodb\lib\connection_string.js:281:15) at new MongoClient (C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongodb\lib\mongo_client.js:62:46) at C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongoose\lib\connection.js:781:16 at new Promise () at NativeConnection.Connection.openUri (C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongoose\lib\connection.js:778:19) at C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongoose\lib\index.js:330:10 at C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongoose\lib\helpers\promiseOrCallback.js:32:5 at new Promise () at promiseOrCallback (C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:10) at Mongoose._promiseOrCallback (C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongoose\lib\index.js:1151:10)
and this is my code:
const mongoose = require('mongoose');
const connectDB = async () => {
const conn = await mongoose.connect(process.env.MONGO_URI,
{
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true
});
console.log(`MongoDB Connected: ${conn.connection.host}`);
};
module.exports = connectDB;
2条答案
按热度按时间h5qlskok1#
似乎与以下内容相同:MongoParseError: options useCreateIndex, useFindAndModify are not supported
来自Mongoose 6.0文档:
不再支持选项useNewUrlParser、useUnifiedTopology、useFindAndModify和useCreateIndex〉〉。Mongoose 6的行为始终假设〉〉useNewUrlParser、useUnifiedTopology和useCreateIndex为真,而〉〉useFindAndModify为假。请从代码中删除这些选项。
来源:https://stackoverflow.com/a/68962378/7860331
6mw9ycah2#
这对我很有效