Can someone help me with this warning?

DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.

const winston = require('winston');
const mongoose = require('mongoose');
const config = require('config');

module.exports = function() {
  const db = config.get('db');

  mongoose.connect(db, {useNewUrlParser: true})
    .then(() =>`Connected to ${db}...`));

What kind of help are you expecting to receive here? We would need to see much more code than what you have provided and much more detailed error messages (.i.e filename with error, line numbers, etc.).

don’t worry this problem is already fixed. I added

mongoose.set(‘useCreateIndex’, true);

This is a MongoDB error. Check the documentation.

thanks! yes it happened when I upgraded the version.

Becareful…$set will create/overwrite an existing Index.

These aren’t the same.

so you are saying I should use:


It depends on the use case. If you want to receive an handle an error if the index already exists I would use collection.ensureIndex(); if you want to clobber the data use $set if you want to update data use set the upsert flag.

Just wanted you to be aware of the difference.


in my case I don’t have a catch() in my connect promise so I guess is set then? what does clobber mean? sorry hispanic speaker here :frowning:

I don’t think clobber is a mongodb term. It just means to replace all the data/overwrite.

I actually have a

Cannot GET /

in localhost:3900 is this due to

mongoose.set(‘useCreateIndex’, true); ?

No, idea. That’s a very vague error. It could be that whatever your GET is pointed to is not a valid path.

Do you have this in a Github repository? If you can share your code we might be able to help.

yes here is my repo the problem is in the movies.js router, all started to crash when I tried to add image upload functionality for this I changed the movie.js model and the movies.js router and now my app is not working, I tried postman and get, post and put have errors, they have trouble with the movieImg: req.file.path that’s what I’m getting. :frowning: I’ll wait patiently if someone could help me this weekend please.

I’ll see if I can look at this later unless someone else can get to it.

no it’s ok I can wait, later is fine :slight_smile:

Can you give me some information so I make sure to configure the mongodb correctly?

What is the DB and table names?

I think I found it in the code but just want to make sure I have the same environment.

the db is vidly and it has :


example of genre

name: “Comedy”

example of movie

title: “Airplane”

ok so right now what I have is the node server running with your cloned repository…

$ nodemon index.js
[nodemon] 1.18.11
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node index.js`
info: Listening on port 3900...
info: Connected to mongodb://localhost/vidly...

Mongodb is listening on 27017

2019-08-23T10:16:39.600-0500 I NETWORK  [initandlisten] waiting for connections on port 27017

I have a DB named ‘vidly’ and a table named ‘users’.

> show dbs
admin          0.000GB
config         0.000GB
local          0.000GB
vidly          0.000GB
> use vidly
switched to db vidly
> show tables

The server isn’t crashing. What’s the next step?

I have a 404 error in postman in the get request http://localhost:3900