Skip to content
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

what kind of error is that Error: useCreateIndex is an invalid option. at Mongoose.set (C:\Users\PC\Desktop\multi-level-marketing-management\app\node_modules\mongoose\lib\index.js:173:48) #10732

Closed
vnxz opened this issue Sep 15, 2021 · 4 comments
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary

Comments

@vnxz
Copy link

vnxz commented Sep 15, 2021

I downloaded old node.js project file and run
here is its db connection file

var mongoDB = "mongodb://admin:admin@localhost:27017/";
var chalk = require('chalk');

var connected = chalk.bold.cyan;
var error = chalk.bold.yellow;
var disconnected = chalk.bold.red;
var termination = chalk.bold.magenta;
require('dotenv').config();

mongoose.ais_mlm = mongoose.createConnection(`${mongoDB}${process.env.DB_NAME}?authSource=admin`, {  
    useNewUrlParser: true,
    useUnifiedTopology: true,
    useFindAndModify: false,
    useCreateIndex: true});

mongoose.connection.on('connected', function(){
    console.log(connected("Mongoose default connection is open to ", mongoDB));
});

mongoose.connection.on('error', function(err){
    console.log(error("Mongoose default connection has occured "+err+" error"));
});

mongoose.connection.on('disconnected', function(){
    console.log(disconnected("Mongoose default connection is disconnected"));
});

process.on('SIGINT', function(){
    mongoose.connection.close(function(){
        console.log(termination("Mongoose default connection is disconnected due to application termination"));
        process.exit(0)
    });
});
module.exports.mongoDB = mongoose;

here is env file

APP_URL_SERVER=http://35.240.172.71:8080
DB_NAME=ais_mlm

when I run this
get the following error
error source come from node modules
I dont know why this happen
can someone explain me
where can I correct to run this file

[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
C:\Users\PC\Desktop\multi-level-marketing-management\app\node_modules\mongoose\lib\index.js:173
  if (VALID_OPTIONS.indexOf(key) === -1) throw new Error(`\`${key}\` is an invalid option.`);
                                         ^

Error: `useCreateIndex` is an invalid option.
    at Mongoose.set (C:\Users\PC\Desktop\multi-level-marketing-management\app\node_modules\mongoose\lib\index.js:173:48)
    at Object.<anonymous> (C:\Users\PC\Desktop\multi-level-marketing-management\app\models\PositionModel.js:4:9)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)   
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)        
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)     
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (C:\Users\PC\Desktop\multi-level-marketing-management\app\Ais\Repository\User.js:10:23)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)   
[nodemon] app crashed - waiting for file changes before starting...
[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
C:\Users\PC\Desktop\multi-level-marketing-management\app\node_modules\mongoose\lib\index.js:173
  if (VALID_OPTIONS.indexOf(key) === -1) throw new Error(`\`${key}\` is an invalid option.`);
                                         ^

Error: `useCreateIndex` is an invalid option.
    at Mongoose.set (C:\Users\PC\Desktop\multi-level-marketing-management\app\node_modules\mongoose\lib\index.js:173:48)
    at Object.<anonymous> (C:\Users\PC\Desktop\multi-level-marketing-management\app\models\PositionModel.js:4:9)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)   
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)        
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)     
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (C:\Users\PC\Desktop\multi-level-marketing-management\app\Ais\Repository\User.js:10:23)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)   
[nodemon] app crashed - waiting for file changes before starting...
@DavideViolante
Copy link
Contributor

DavideViolante commented Sep 16, 2021

This option is deprecated since v6 if I'm not mistaken, try to remove it from the options object.

@vnxz
Copy link
Author

vnxz commented Sep 16, 2021

This option is deprecated since v6 if I'm not mistaken, try to remove it from the options object.

thanks bro for pointing the error
I edited some part of code
finally , one error still happen
that due to custom localhost url

DATA = "mongodb://admin:admin@localhost:27017/ais_mlm?authSource=admin"

when use this url
db connection failed
but with this url .db connect success

DATA = "mongodb://localhost:27017/ais_mlm"

I want to know is how can correct this error by custom localhost url
this also use chalk for custom url
but error still happen
How can fix it

const mongoose = require("mongoose");
//const mongoDB = "mongodb://admin:admin@localhost:27017/ais_mlm?authSource=admin";
const chalk = require('chalk');
const path = require('path');
const connected = chalk.bold.cyan;
const error = chalk.bold.yellow;
const disconnected = chalk.bold.red;
const termination = chalk.bold.magenta;
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
console.log('here...', path.resolve(__dirname, '../.env'),process.env.DATA);

 mongoose.connect(process.env.DATA, async(err)=>{
    if(err) throw err;
    console.log("conncted to db")
  }
 );

mongoose.connection.on('connected', function(){
    console.log(connected("Mongoose default connection is open to ", process.env.DATA));
});

mongoose.connection.on('error', function(err){
    console.log(error("Mongoose default connection has occured "+err+" error"));
});

mongoose.connection.on('disconnected', function(){
    console.log(disconnected("Mongoose default connection is disconnected"));
});

process.on('SIGINT', function(){
    mongoose.connection.close(function(){
        console.log(termination("Mongoose default connection is disconnected due to application termination"));
        process.exit(0)
    });
});

here is error output

Mongoose default connection is disconnected
Mongoose default connection has occured MongoServerError: Authentication failed. error
(node:22380) UnhandledPromiseRejectionWarning: MongoServerError: Authentication failed.
    at MessageStream.messageHandler (C:\Users\PC\Desktop\multi-level-marketing-management\app\node_modules\mongodb\lib\cmap\connection.js:467:30)
    at MessageStream.emit (events.js:315:20)
    at processIncomingData (C:\Users\PC\Desktop\multi-level-marketing-management\app\node_modules\mongodb\lib\cmap\message_stream.js:108:16)
    at MessageStream._write (C:\Users\PC\Desktop\multi-level-marketing-management\app\node_modules\mongodb\lib\cmap\message_stream.js:28:9)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at MessageStream.Writable.write (internal/streams/writable.js:303:10)
    at Socket.ondata (internal/streams/readable.js:719:22)
    at Socket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:22380) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:22380) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I think uername is admin password is admin

how can auth this credentials in mondb
here is its database
but still not insert any data

Screenshot_1

Screenshot_2

it make nonsense why cannot access
Screenshot_3

@IslandRhythms IslandRhythms added the help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary label Sep 16, 2021
@vkarpov15
Copy link
Collaborator

@vnxz the error you're getting is "authentication failed", so that means you're not providing the correct username, password, or authSource. I suspect the issue is that you're manually inserting users from the mongodb shell, rather than creating them using the MongoDB shell's createUser() function.

@lakshmankashyap
Copy link

useCreateIndex is no longer necessary in Mongoose 6, please remove it when you upgrade

@Automattic Automattic locked and limited conversation to collaborators Dec 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Projects
None yet
Development

No branches or pull requests

5 participants