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.

Image of Quadratic

Python + AI + Spreadsheet

Chat with your data and get insights in seconds with the all-in-one spreadsheet that connects to your data, supports code natively, and has built-in AI.

Try Quadratic free

Top comments (0)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay