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