• Register
0 votes
2.1k views

Problem :

I am getting following error:

Deprecationwarning: collection.ensureindex is deprecated. use createindexes instead.     

Where is above error coming from? I am not at all using ensureIndex or createIndex in my Nodejs application anywhere. I am using the yarn package manager.

Please find below my code in index.js

import express from 'express';
import path from 'path';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import Promise from 'bluebird';
dotenv.config();
mymongoose.Promise = Promise;
mymongoose.connect('mongodb://localhost:27017/bookworm', { useNewUrlParser: true });
const myapp = express();

Does anyone ever faced this issue? Any solution on it?

6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

The issue is that the mongoose still uses the collection.ensureIndex and must be updated by them in the near future. So to get rid of your error message you can downgrade it by using version 5.2.8 in your package.json and also delete any caches, last resort is to uninstall it the install it with npm install mongoose@5.2.8:

"mongoose": "^5.2.8"

Per mongoose docs please follow below steps:

mongoose.set('useNewUrlParser', true);
mongoose.set('useFindAndModify', false);
mongoose.set('useCreateIndex', true);

Replace update() with updateOne(), updateMany(), or replaceOne()

Replace remove() with deleteOne() or deleteMany().

Replace count() with countDocuments(), Here unless you want to count how many documents are in the whole collection (no filter). In the latter case, please use estimatedDocumentCount().

9 7 4
38,600 points

Related questions

0 votes
1 answer 6 views
6 views
Problem: Any help, I will be so thankful: Deprecationwarning: collection.ensureindex is deprecated. use createindexes instead.
asked Mar 14 Wafa Abu Yousef 6.1k points
0 votes
1 answer 4 views
4 views
Problem: I need someone’s help to fix it. Mongoerror: e11000 duplicate key error collection:
asked Mar 21 Ifra 24.4k points
0 votes
1 answer 5 views
5 views
Problem: I am using node with express + mongoose and trying to use passport.js with restful api. I keep getting this exception after authentication success (I see the callback url on the browser): Passport.initialize() middleware not in use
asked Apr 2 ummesalma 22.6k points
0 votes
1 answer 15 views
15 views
Problem: cannot read property 'symbol(symbol.iterator)' of undefined.
asked Feb 16 charles mathews 5.5k points
0 votes
1 answer 211 views
211 views
Problem : I have recently updated the node to 7.2.1 and noticed that there is the warning coming as below : (node:4346) DeprecationWarning: Calling an asynchronous function without callback is deprecated. Why is this 4346 ? I only have 2000 lines of code in the js file, so it must not be the line-number. Where should I look for that code?
asked Dec 10, 2019 alecxe 7.5k points
0 votes
1 answer 42 views
42 views
Problem: I am a beginner to node.js, cordova and npm.When I try below command: $ npm install -g cordova@latest I always face below error: “Npm WARN deprecated node-uuid@1.4.8: Use uuid module instead.” Below are my system details: mac Os Sierra 10.12 ... each and every suggestion and also tried to install or uninstall the hundred times. I want to know is it a npm or cordova problem?
asked Aug 29, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 14 views
14 views
Problem: Did anybody face the same issue: It looks like you are trying to access mongodb over http on the native driver port.
asked Mar 14 Wafa Abu Yousef 6.1k points
0 votes
1 answer 603 views
0 votes
1 answer 409 views
409 views
Problem: I have fundamental knowledge of node.js, mongodb and expressjs. Currently I am trying to use the expressjs only for a backend. I also want to store data into a mongodb using the express. All of my view part is completely done in zend. I do not need the view to be in ... is how I have tried to redirect it to index.js app.get("/index",function(req,res){ console.log("route to index"); });
asked Aug 13, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 2.1K views
2.1K views
Problem : When I try to open the terminal and enter the following command: sudo mongod The output is received as below: [initandlisten] waiting for connections on port 27017 When I try to open another terminal and enter following command: sudo mongo I will open the mongo ... never posts the data. So I think my problem lies within mongo but I am unable to figure it out. POST /info 200 120002ms
asked Dec 12, 2019 alecxe 7.5k points