• Register
0 votes
1.4k 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

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 12 views
12 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 Raphael Pacheco 4.9k points
0 votes
1 answer 140 views
140 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 11 views
0 votes
1 answer 37 views
37 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 Raphael Pacheco 4.9k points
0 votes
1 answer 1.1K views
1.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