DEV Community

Ravi Kumar Gupta
Ravi Kumar Gupta

Posted on

MongoDB Start with no-indexing

Using MongoDB?

Ever faced this problem when your app is collecting huge data every day that any moment it may completely fill your storage and leave you with zero bytes.

After that, you can’t even login to the machine to fix the problem.

In your app, you can keep monitoring the free space and delete the old MongoDB data. But.. what if -

You have free space left, and MongoDB is re-building or building indexes and before your app checks again, the free space goes to zero?

But, you’re lucky to observe this before it happens. You go to MongoDB prompt and try to delete the data, but alas, MongoDB is building the indexes on the same collection you want to delete data from.

You won’t be able to do that.

You restart MongoDB hoping it would stop indexing and you would be able to delete.

That, doesn’t work either.

Okay, so you need to do this — start MongoDB with —-noIndexBuildRetry flag.

Edit the /etc/init.d/mongod file and replace the line —

- OPTIONS=" -f $CONFIGFILE"
Enter fullscreen mode Exit fullscreen mode

with

- OPTIONS=" -f $CONFIGFILE --noIndexBuildRetry"
Enter fullscreen mode Exit fullscreen mode

Restart MongoDB after the update. MongoDB will not attempt to fix or rebuild indexes.

Delete what you want from MongoDB prompt. Ensure to keep safe free space considering the indexes size.

Edit the /etc/init.d/mongod file again to remove the --noIndexBuildRetry and save.

Restart MongoDB.

Did it save your time? Let me know in the comments.

You can follow me on Twitter — @kravigupta . You can also connect on LinkedIn — kravigupta.

Top comments (0)