{"version":"1.0","type":"rich","title":"$centerSphere query hangs mongodb","description":"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\n\n## Description\n\nThis 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.\n\nThe key elements shown include:\n\n1. **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.\n\n2. **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.\n\n3. **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.\n\n4. **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.\n\nThe 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.\n\nYour job is to write a 150-word description of this example, for a\nvisualization gallery, in English, using no lists, no markdown, no\nlinks, no code, no special formatting.\n\nA good description starts with a one-sentence summary that mentions the\ntitle, the author, and the type of visualization (e.g., \"Timeline\", \"Scatter\nplot\", \"Map\"). It then explains what the visualization shows, why it was made,\nand a key feature or takeaway. It is written for a general audience, in plain\nlanguage, and stays concise.  Do NOT speculate about the author's motives.\n\nDo not use markdown, do not use bullet lists. The description should\nbe a single paragraph of prose.\n\nA good description will be between 60 and 120 words. Try to stay within this\nlimit.\n\nDo not mention the files or file names. Do not include more than one\nexample sentence of code. Write the description for a non-technical audience. Avoid\ndomain jargon. Use simple words and short sentences. Do not talk about the\ndata, but about the visualization. (Remember: this is for a visualization\ngallery.)\n\nRemember to start with a short title. The title is not part of the description,\nbut precedes it. Use an unordered list after the description to list the\nvisualization techniques used.# $centerSphere Query Hangs MongoDB\n\nThis 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.\n\n## Visualization Techniques\n\n- **Process/Thread State Visualization**: Thread stacks illustrating system-level blocking\n- **Query Timeline**: Showing the long-running operation (210+ seconds) versus the blocked administrative query\n- **Index and Collection Overview**: Summarizing the schema and indexes on the 27M-record collection\n- **Command/Response Pairs**: Raw MongoDB shell output as evidence of the hang","provider_name":"VizHub AI Studio","provider_url":"https://next.vizhub.com","html":"<iframe src=\"https://next.vizhub.com/viz/gist-4555130?mode=embed\" width=\"960\" height=\"500\" scrolling=\"no\" frameborder=\"1\"></iframe>","width":960,"height":500,"cache_age":3600}