Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8352215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:54:02+00:00 2026-06-09T08:54:02+00:00

I have a PHP app that interacts with MongoDB. Until recently, the app was

  • 0

I have a PHP app that interacts with MongoDB. Until recently, the app was working fine but a few days back I found that the app is starting to respond REALLY slow. One of the collections has shot up to 500K+ records. So the MongCursor for any query on that collection keeps timing out.

I don’t think 500K records is WAY too much. Other pages using mongodb are beginning to slow down as well, but not as much as the one which uses the collection with 500k records. Static pages which don’t interact with MongoDB are still fast to respond.

I am not sure what could be the issue here. I have indexed the collections, so that does not seem to be a problem. Another point to note is that the RAM spec on the server is 512 MB and when PHP executes Mongo, top command show 15000k memory free.

Any help will be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:54:04+00:00Added an answer on June 9, 2026 at 8:54 am

    To summarize followup from the chat room, the issue is actually related to a find() query which is doing a scan of all ~500k documents to find 15:

    db.tweet_data.find({ 
        $or: 
        [ 
            { in_reply_to_screen_name: /^kunalnayyar$/i, handle: /^kaleycuoco$/i, id: { $gt: 0 } }, 
            { in_reply_to_screen_name: /^kaleycuoco$/i, handle: /^kunalnayyar$/i, id: { $gt: 0 } } 
        ], 
        in_reply_to_status_id_str: { $ne: null }
    } ).explain() 
    { 
        "cursor" : "BtreeCursor id_1", 
        "nscanned" : 523248, 
        "nscannedObjects" : 523248, 
        "n" : 15, 
        "millis" : 23682, 
        "nYields" : 0, 
        "nChunkSkips" : 0, 
        "isMultiKey" : false, 
        "indexOnly" : false, 
        "indexBounds" : { 
            "id" : [ 
                [ 
                    0, 
                    1.7976931348623157e+308 
                ] 
            ] 
        } 
    }
    

    This query is using case-insensitive regular expressions which won’t make efficient use of an index (though there wasn’t actually one defined, in this case).

    Suggested approach:

    • create lowercase handle_lc and inreply_lc fields for search purposes

    • add a compound index on those:

      db.tweet.ensureIndex({handle_lc:1, inreply_lc:1})

    • the order of the compound index allows efficient find of all tweets either by handle or by (handle,in_reply_to)

    • search by exact match instead of regex:


    db.tweet_data.find({
    $or:
    [
    { in_reply_to_screen_name:'kunalnayyar', handle:'kaleycuoco', id: { $gt: 0 } },
    { in_reply_to_screen_name:'kaleycuoco', handle:'kunalnayyar', id: { $gt: 0 } }
    ],
    })

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my php app working fine, performing some other Graph API functions. However,
I have a PHP app that creates a CSV file which is forced to
I have a simple PHP app that prints 'hello world'. When I run it
I have a legacy PHP/MySQL app that calls mysql_connect(). Tons of existing downstream code
If I have in my php app an object that connects to the database,
I have written a small chat app that uses mysql + php to facilitate
OK, I have a web app that uses PHP, MySQL and JavaScript. In an
I have a php script that inserts data from an Android app into a
I have a php web service that takes the request from android/iphone app and
I'm writing a simple web app in PHP that needs to have write access

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.