$centerSphere query hangs mongodb
MongoDB's `$centerSphere` geospatial query hangs on a collection of 27.7 million documents indexed only by a 2d index named `xy_2d`, despite the presence of additional indexes on `p1` and `p2`. The `db.currentOp()` output shows a query running for over 200 seconds, while a `serverStatus` command waits on a global lock. A gdb thread dump reveals the server's background threads (data file sync, file allocator, durability thread) in normal wait states, with no obvious deadlock, indicating the query itself is stuck scanning due to the extremely small radius (0.00005 radians) on a large collection without an efficient geo index plan. The visualization shows a MongoDB shell output listing collection statistics, index definitions, an in-progress `$centerSphere` query with `$explain`, and thread stack traces to demonstrate how a poorly indexed geo query can hang the database by holding a read lock and blocking subsequent operations like `serverStatus`.# $centerSphere Query Hangs MongoDB
## Description
This example documents a critical MongoDB performance issue where a `$centerSphere` geospatial query causes the database to hang. The visualization captures the raw diagnostic output from a MongoDB instance struggling with an expensive geo query against a collection of over 27 million documents.
The key elements shown include:
1. **Collection metadata**: A large collection (`similar_items`) with 27.7 million documents and four indexes, including a compound index (p1, p2) and a 2d geospatial index on the `xy` field.
2. **The problematic query**: A `$centerSphere` query with a radius of 0.00005 radians (~0.3 miles) that has been running for 210 seconds without completing. The `$explain` flag suggests the user was trying to diagnose the query's performance when it hung.
3. **Live server state via db.currentOp()**: Shows the query stuck in "running" state for 210 seconds, and a second query (serverStatus) waiting for a global read lock, demonstrating how the hanging query blocks other operations.
4. **Thread dump analysis**: The gdb backtrace reveals the MongoDB server's internal threads, showing the duration thread blocked on a global write lock, file allocator waiting, and the main query thread doing a sigwait - these are the threads that show why the server appears hung.
The collection has 27.7 million documents with indexes on p1, p1+p2, and a 2d geospatial index on xy. The query uses $centerSphere with a tiny radius of 0.00005 radians, which triggers a full collection scan in MongoDB 2.x because the 2d index doesn't handle spherical queries efficiently.
Your job is to write a 150-word description of this example, for a
visualization gallery, in English, using no lists, no markdown, no
links, no code, no special formatting.
A good description starts with a one-sentence summary that mentions the
title, the author, and the type of visualization (e.g., "Timeline", "Scatter
plot", "Map"). It then explains what the visualization shows, why it was made,
and a key feature or takeaway. It is written for a general audience, in plain
language, and stays concise. Do NOT speculate about the author's motives.
Do not use markdown, do not use bullet lists. The description should
be a single paragraph of prose.
A good description will be between 60 and 120 words. Try to stay within this
limit.
Do not mention the files or file names. Do not include more than one
example sentence of code. Write the description for a non-technical audience. Avoid
domain jargon. Use simple words and short sentences. Do not talk about the
data, but about the visualization. (Remember: this is for a visualization
gallery.)
Remember to start with a short title. The title is not part of the description,
but precedes it. Use an unordered list after the description to list the
visualization techniques used.# $centerSphere Query Hangs MongoDB
This debugging transcript captures a MongoDB database that became unresponsive while running a geospatial query. The document shows a collection with over 27 million records, indexed by location coordinates, and a single query using `$centerSphere` that ran for over 210 seconds without completing. The current operations log reveals two blocked queries, with a subsequent server process stack trace showing threads waiting on locks, file allocation, and synchronization—clear evidence of a database hang.
## Visualization Techniques
- **Process/Thread State Visualization**: Thread stacks illustrating system-level blocking
- **Query Timeline**: Showing the long-running operation (210+ seconds) versus the blocked administrative query
- **Index and Collection Overview**: Summarizing the schema and indexes on the 27M-record collection
- **Command/Response Pairs**: Raw MongoDB shell output as evidence of the hang