Kristina Chodorow has a post where she discusses a few tweaks you can make to your code to improve performance in MongoDB.
Some of the recommendations at a high level are basic, such as the recommendation to not waste any connections. However, there are some pretty interesting side effects with the PHP connection code.
$connection = new Mongo();
$connection->connect();
In the previous code it appears the user wants to create a new connection. However, under the hood the following is happening:
- The constructor connects to the database.
connect() sees that you’re already connected, assumes you want to reset the connection.
- Disconnects from the database.
- Connects again.
The result is that you have doubled your execution time. This is just one example of many that Kristina provides. If you are using MongoDB I'd suggest you check it out.
Read more: Oh, the Mistakes I've Seen