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 7987255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:05:38+00:00 2026-06-04T12:05:38+00:00

I’m using PHP and mongodb. I’ve turned on system profiling on everything above 20ms,

  • 0

I’m using PHP and mongodb. I’ve turned on system profiling on everything above 20ms, using mongodb 2.0.4. When I load a simple page with every little query, it records in the system profile the same query like 4, 10, sometimes 24 times! And the pages load very slow because of that! Why is that happening??

The query can be as simple as:

$c2 = $things->find();
        foreach($c2 as $doc) {
            // some code...
        }

Thanks!!

EDIT: Full code:

<?php

$m = new Mongo();
$db = $m->selectDB("test");


function getAllData ($db) {

    $some = $db->some;

        $cursor = $some->find();


        $js = "function() {
        return ((";

        foreach ($cursor as $doc) {
            $js .= "this.idE == '" . $doc['_id'] .  "' || ";

        }
        $js = substr($js,0,-4);
        $js .= ")";
        $js .= ");}";

        $names = $db->names;
        $c2 = $names->find(array('$where' => $js));
        foreach($c2 as $doc) {
            echo $doc['name'];
        }

}

getAllData ($db);


?>
  • 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-04T12:05:40+00:00Added an answer on June 4, 2026 at 12:05 pm

    Which of the two queries is getting multiplied?

    I would start modifying the code and see what happens. The first thing that I would do is remove the “foreach” and instead just do one “getNext” and see if this affects the number of times the query is called. My best guess is that it has something to do with the way the Mongo driver fetches results in batches. When you do a query, it doesn’t download all the rows at once, it downloads them in batches. You may be seeing these batch fetches as duplicate queries. I think that there is a mechanism by which you can adjust the batch size, which may help. Also, updating to the latest drivers may help.

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

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I am reading a book about Javascript and jQuery and using one of the

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.