Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Problems caused by mongodb indexing

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Indexing is a problem that can easily lead to long-term write locks. MongoDB needs to occupy a write lock when building indexes in the foreground (and will not give up temporarily). If the amount of data in the collection is large, indexing usually takes a long time, which is especially easy to cause problems.

The solution is very simple. MongoDB provides two kinds of indexing access, one is background, which does not need to occupy the write lock for a long time, and the other is non-background.

It takes a long time to occupy the lock. The problem can be solved using the background approach.

For example, index the oversized table posts

Never use it.

Db.posts.ensureIndex ({user_id: 1})

Instead, you should use the

Db.posts.ensureIndex ({user_id: 1}, {background: 1})

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report