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 .