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

Suppressing: DeprecationWarning: 'ensureIndex()' is deprecated in Mongoose >= 4.12.0, use 'createIndex() #5692

Closed
MongoExpUser opened this issue Oct 4, 2017 · 19 comments
Labels
needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity

Comments

@MongoExpUser
Copy link

How can we suppress the following warning in Mongoose 4.12.0, when connecting MongoDB with mongoose. This warning message only appears when I upgraded to 4.12.0.

DeprecationWarning: 'ensureIndex()' is deprecated in Mongoose >= 4.12.0, use 'createIndex()' instead

@amihailes
Copy link

This arrives with a mongoDB 3.4.7 on my machine.

@lcaouen
Copy link

lcaouen commented Oct 6, 2017

I have the same issue with:

  • Mongoose 4.12.0
  • MongoDB 3.2.16
  • NodeJS 6.11.3

@vkarpov15
Copy link
Collaborator

That's strange. Are you calling ensureIndexes() manually? Can you show me your connection code? Mongoose 4.12 should call createIndex() under the hood.

@vkarpov15 vkarpov15 added the needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity label Oct 7, 2017
@ghost
Copy link

ghost commented Oct 7, 2017

I'm not using ensureIndex() anywhere in my project and I still get this error with v4.12.0.

  mongoose.Promise = global.Promise;
  mongoose.connect(config.MONGO_URI, {
    useMongoClient: true,
    promiseLibrary: global.Promise
  });
  this.connection = mongoose.connection;

@MongoExpUser
Copy link
Author

MongoExpUser commented Oct 7, 2017

I'm not using or calling ensureIndex() anywhere in my code. See below:

var mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
var fs = require('fs');
var uri = 'mongodb://user:password@domain.com/dbName';
var optionsSSL = { //read in certs};
var connectionOptions = { //specify connection options including OptionsSSL};

mongoose.connect(uri, connectionOptions, function(err)
{
if (err) {console.log(err)};
});

I also feel that this is a strange behavior.

May be this has to do with the MongoDB server version?

I am using MongoDB server version: 3.4.9.

@xiao-xiansheng
Copy link

encounter the same problem
mongoose.connect('mongodb://127.0.0.1:27017/text',{ useMongoClient: true},function(err){
if (err) {
console.log('-----------NO------------');
}else{
console.log('-----------OK------------');
}
});
setting session

store: new MongoStore({
mongooseConnection: mongoose.connection,
autoRemove:'native'
})

@ivancsicsmarkus
Copy link

I've tested things out. MongoStore causes this notice.

@amihailes
Copy link

I use also MongoStore.

It seems to be an issue with the combination mongoose/MongoStore

Nodejs 6.11.14
mongoose 4.12.0
MongoDB 3.4.9

@ghost
Copy link

ghost commented Oct 7, 2017

There's an open pull request in connect-mongo to fix this issue.
jdesboeufs/connect-mongo#269

@MongoExpUser
Copy link
Author

MongoExpUser commented Oct 7, 2017

I can also confirm that the warning message is from the mongo "store" module that I am using for session management, which is connect-mongo.

So replacing connect-mongo with another "store" management module that calls createIndex() should eliminate the warning.

In the alternative, I think there is an open pull request in connect-mongo to fix the issue as mentioned by CivFactions.

Thank you all.

@ac1dr3d
Copy link

ac1dr3d commented Oct 7, 2017

same here people but... this MongoStore thing is in my react project also... i mean, its built in... not my code. so... id be glad to hear solution... please. thanks.

@MongoExpUser
Copy link
Author

MongoExpUser commented Oct 7, 2017

ac1dr3d,
If your mongoStore is using connect-mongo, then you have to wait until the issue is resolve on connect-mongo. It is currently under an open pull request as mentioned by CivFactions.

If you want to replace your mongoStore with another module, check the links below for recommended modules:

  1. express-session-mongo: https://www.npmjs.com/package/express-session-mongo
  2. connect-mongodb-session: https://www.npmjs.com/package/connect-mongodb-session
  3. sessionstore: https://www.npmjs.com/package/sessionstore
  4. express-mongoose-store: https://www.npmjs.com/package/express-mongoose-store
  5. etc..

@amihailes
Copy link

Hi,

I use express-session-mongo and I have the warning.........

@amihailes
Copy link

In fact, express-session + connect-mongodb-session:

session = require('express-session'),
MongoDBStore = require('connect-mongodb-session')(session),

@MongoExpUser
Copy link
Author

MongoExpUser commented Oct 8, 2017

amihailes,
It means that connect-mongodb-session is probably calling ensureIndex() somewhere under the hood. So, it might be worth trying other modules listed above or others that could be found on npm to see which ever works for you.

@jdesboeufs
Copy link

Working on this!

@jdesboeufs
Copy link

jdesboeufs commented Oct 9, 2017

Published connect-mongo@2.0.0
See CHANGELOG

@ghost
Copy link

ghost commented Oct 9, 2017

Thanks @jdesboeufs

@MongoExpUser
Copy link
Author

Thank you jdesboeufs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity
Projects
None yet
Development

No branches or pull requests

8 participants