New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Options passed in mongoose.connect() function cause error #10632
Comments
This is a breaking change in Mongoose 6, those 4 options should be removed from mongoose.connect() in version 6. |
other options except useNewUrlParser, useUnifiedTopology, useFindAndModify, and useCreateIndex still cause the error |
which ones? |
useCreateIndex and useFindAndModify -> MongoParseError option ... is not supported Maybe it causes this Issue #10631 ? |
Again, according to https://mongoosejs.com/docs/migrating_to_6.html#no-more-deprecation-warning-options |
@lorand-horvath Thanks for your clarification! /** Opens Mongoose's default connection to MongoDB, see [connections docs](https://mongoosejs.com/docs/connections.html) */
export function connect(uri: string, options: ConnectOptions, callback: CallbackWithoutResult): void;
export function connect(uri: string, callback: CallbackWithoutResult): void;
export function connect(uri: string, options?: ConnectOptions): Promise<Mongoose>; interface ConnectOptions extends mongodb.MongoClientOptions {
/** Set to false to [disable buffering](http://mongoosejs.com/docs/faq.html#callback_never_executes) on all models associated with this connection. */
bufferCommands?: boolean;
/** The name of the database you want to use. If not provided, Mongoose uses the database name from connection string. */
dbName?: string;
/** username for authentication, equivalent to `options.auth.user`. Maintained for backwards compatibility. */
user?: string;
/** password for authentication, equivalent to `options.auth.password`. Maintained for backwards compatibility. */
pass?: string;
/** Set to false to disable automatic index creation for all models associated with this connection. */
autoIndex?: boolean;
/** Set to `true` to make Mongoose automatically call `createCollection()` on every model created on this connection. */
autoCreate?: boolean;
} |
I managed to run with the following configuration: const connectionResult = await callTryCatch<Mongoose, Error>(() =>
connect(`mongodb://${DB_SERVER}:${DB_PORT}`, {
dbName: DB_NAME,
auth: {
password: DB_PASS,
username: DB_USER_NAME,
},
})
); I'm using v Good luck. |
Thanks. I was following around with a MERN stack tutorial, using Mongoose v6.0.2, and I was getting some weird errors. I tried commenting |
Possible opportunity to update typescript docs here |
as mentioned here Automattic#10632
Hey, I've solve this with this import in index.ts file - const mongoose = require("mongoose"); |
Do you want to request a feature or report a bug?
bug
What is the current behavior?
An error occurs when trying to connect to a MongoDB
Connection Code
Error Message
If the current behavior is a bug, please provide the steps to reproduce.
"mongoose": "^6.0.2"
mongoose.connect()
tsconfig.json
What is the expected behavior?
Should be able to pass in an
options
object to theconnect()
function with the following options.What are the versions of Node.js, Mongoose, and MongoDB you are using? Note that "latest" is not a version.
Node.js: v16.7.0
Mongoose: 6.0.2
MongoDB: 4.4.8
The text was updated successfully, but these errors were encountered: