Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Very slow query

Received: by 10.59.7.234 with SMTP id df10mr5088778ved.23.1347281426673;
        Mon, 10 Sep 2012 05:50:26 -0700 (PDT)
X-BeenThere: mongodb-user@googlegroups.com
Received: by 10.52.92.207 with SMTP id co15ls1594996vdb.5.gmail; Mon, 10 Sep
 2012 05:50:18 -0700 (PDT)
Received: by 10.52.66.235 with SMTP id i11mr444980vdt.7.1347281418178;
        Mon, 10 Sep 2012 05:50:18 -0700 (PDT)
Date: Mon, 10 Sep 2012 05:50:17 -0700 (PDT)
From: marcandre <malegr...@gmail.com>
To: mongodb-user@googlegroups.com
Message-Id: <2fb72d20-018d-4970-82a1-865bc7b4e6ca@googlegroups.com>
Subject: Very slow query
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_818_981441.1347281417886"

------=_Part_818_981441.1347281417886
Content-Type: multipart/alternative; 
	boundary="----=_Part_819_19863549.1347281417886"

------=_Part_819_19863549.1347281417886
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Good afternoon,
 
I'am using MongoDB with 350 000 documents and php. The problem is the php 
reads documents very slowly .
 
When I'm updating documents I drop the database and I insert the documents 
: during this processus the inserts are very long .
 
I don't understand, I putted indexes .
 
I show you a piece of my php code when I updating documents : 
 
$cnx_mongo = new Mongo("127.0.0.1", array("persist" => "x"));
 
 $db = $cnx_mongo->my_database;
 $ma_collection = $db->my_collection;
 
 $response = $ma_collection->drop();
 $response = $db->drop();
 
 $db = $cnx_mongo->my_database;
 $ma_collection = $db->my_collection;
 
 
 ///I Import data from a database Postgres 
 

 ///I put index in a fiel named tags 
 $ma_collection->ensureIndex("tags");
 
This is the code when php reads documents :
 
///Research of documents who containts key words
$cnx_mongo = new Mongo("127.0.0.1", array("persist" => "x"));
$db = $cnx_mongo->my_database;
$ma_collection = $db->my_collection;

 //Get back keywords researching by tags fields
 $who = array();
 if(count($ArrayWord) > 1) { 
  $tmp = array(); 
  foreach ($ArrayWord as $q) { 
   $tmp[] = new MongoRegex( "/". strtolower($q) ."/" ); 
  }
  
  $who['tags'] = array('$all' => $tmp); 
  
 }else{ 
  $who['tags'] = new MongoRegex( "/". strtolower($mot) ."/" ); 
 } 

 $cursor = $ma_collection->find($who)->limit(30)->skip(60);
 
 $cursor->timeout(1000);
 
 print($cursor->count()); // I display the number of documents 
 
 foreach($cursor as $obj){
  ///I display the results of document  
 }
 
 
The tags field containts array keywords .
 
What should I do to resolve this problem ?
 
I checked the RAM (6 Go of physical RAM and 4 Go of available memory) .
 
How can I check the cause of this slow reads and inserts ?
 
I there is something to configure in mongodb ?
 
Best regards .

------=_Part_819_19863549.1347281417886
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<div>Good afternoon,</div><div>&nbsp;</div><div>I'am using MongoDB with 350=
 000 documents and php. The problem is the php reads documents very&nbsp;sl=
owly .</div><div>&nbsp;</div><div>When I'm&nbsp;updating&nbsp;documents&nbs=
p;I drop the database and I insert the documents : during this processus th=
e inserts are very long .</div><div>&nbsp;</div><div>I don't understand, I =
putted indexes .</div><div>&nbsp;</div><div>I show you&nbsp;a piece of my p=
hp code when I updating&nbsp;documents : </div><div>&nbsp;</div><div>$cnx_m=
ongo =3D new Mongo("127.0.0.1", array("persist" =3D&gt; "x"));<br>&nbsp;<br=
>&nbsp;$db =3D $cnx_mongo-&gt;my_database;<br>&nbsp;$ma_collection =3D $db-=
&gt;my_collection;<br>&nbsp;<br>&nbsp;$response =3D $ma_collection-&gt;drop=
();<br>&nbsp;$response =3D $db-&gt;drop();<br>&nbsp;<br>&nbsp;$db =3D $cnx_=
mongo-&gt;my_database;<br>&nbsp;$ma_collection =3D $db-&gt;my_collection;<b=
r>&nbsp;<br>&nbsp;</div><div>&nbsp;///I Import data from a database Postgre=
s <br>&nbsp;</div><div><br>&nbsp;///I put index in a fiel named tags </div>=
<div>&nbsp;$ma_collection-&gt;ensureIndex("tags");</div><div>&nbsp;</div><d=
iv>This is the&nbsp;code when php reads documents :</div><div>&nbsp;</div><=
div>///Research of documents who containts key words</div><div>$cnx_mongo =
=3D new Mongo("127.0.0.1", array("persist" =3D&gt; "x"));<br>$db =3D $cnx_m=
ongo-&gt;my_database;<br>$ma_collection =3D $db-&gt;my_collection;</div><di=
v><br>&nbsp;//Get back keywords researching by tags fields</div><div>&nbsp;=
$who =3D array();<br>&nbsp;if(count($ArrayWord) &gt; 1) { <br>&nbsp;&nbsp;$=
tmp =3D array(); <br>&nbsp;&nbsp;foreach ($ArrayWord as $q) { <br>&nbsp;&nb=
sp;&nbsp;$tmp[] =3D new MongoRegex( "/". strtolower($q) ."/" ); <br>&nbsp;&=
nbsp;}<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;$who['tags'] =3D array('$all' =3D&gt;=
 $tmp); <br>&nbsp; <br>&nbsp;}else{ <br>&nbsp;&nbsp;$who['tags'] =3D new Mo=
ngoRegex( "/". strtolower($mot) ."/" ); <br>&nbsp;} </div><div><br>&nbsp;$c=
ursor =3D $ma_collection-&gt;find($who)-&gt;limit(30)-&gt;skip(60);<br>&nbs=
p;<br>&nbsp;$cursor-&gt;timeout(1000);</div><div>&nbsp;</div><div>&nbsp;pri=
nt($cursor-&gt;count()); // I display the number of documents </div><div>&n=
bsp;</div><div>&nbsp;foreach($cursor as $obj){</div><div>&nbsp;&nbsp;///I d=
isplay the results of document&nbsp; <br>&nbsp;}</div><div>&nbsp;</div><div=
>&nbsp;</div><div>The tags field containts array keywords .</div><div>&nbsp=
;</div><div>What should I do to resolve this problem ?</div><div>&nbsp;</di=
v><div>I checked the RAM (6 Go of physical RAM and 4 Go of available memory=
) .</div><div>&nbsp;</div><div>How can I check the cause of this slow reads=
 and inserts ?</div><div>&nbsp;</div><div>I there is something to configure=
 in mongodb ?</div><div>&nbsp;</div><div>Best regards .</div>
------=_Part_819_19863549.1347281417886--

------=_Part_818_981441.1347281417886--