Get the App
SLTechnology News&Howtos  ›  Database  › 

Problems caused by mongodb indexing

Shulou Source: shulou.com Published: 2022-06-01 09:40:13 10月02日 Update

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})

Tags: Index long-term problem way big no foreground that is data method right and wrong Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Docker Xiaomi Apple MariaDB