Q:

codeigniter mongodb performance

When i am running my mongodb query in shell, i get results set in few milliseconds. and when i execute this same query in codeigniter i get results in 12 seconds.
Shell script
db.order.find({customer_email:/^asd@asd.com/}).explain()

Codeigniter script
$orderData = $this->mongo_db->get_where('order', array('customer_email'=> new MongoRegex("/^asd@asd.com/i")));

Is there any solution to optimize speed of fetching results?
There are 7272699 total records and i need to find asd@asd.com.

A:

First, you should set an index on customer_email if not already. Second, try to remove the i flag in the MongoRegex to use the index:
$orderData = $this->mongo_db->get_where('order', array('customer_email'=> new MongoRegex("/^asd@asd.com/")));

