MongoDB is a fast, robust and highly scalable database. It works on many platforms and has many language drivers for its optimal usage. MongoDB is growing day by day and one should have clear understanding of its basics as well as tips for better usage. Click here to read Part One...
Welcome to Part Two of the MongoDB Tips blog. I have divided these tips across many sections of topics in MongoDB. They include Optimization, Performance, Speed, Indexing, Schema Design, and Data Safety. Happy Reading.
Tip 1 #
Learn to Use –notablescan Option in Development however NOT in PRODUCTION.
Img Source: www.percona.com
MongoDB has an option --notablescan, this returns an error when a query has to do a full table scan. This can be handy in development if you want to make sure that all of your queries are hitting indexes, however, do not use it in a production environment as it might cause performance issues. The problem is that many simple admin tasks require table scans. This option allows to see the list of collections in your database that takes a full table scan.
Tip 2 # Manage All the Servers & Databases from a Single SHELL
By default, Mongo connects to localhost: 27017. You can connect to any server on startup by running mongo host: port/database. You can also connect to multiple servers or databases within the shell.
For example, suppose we have an application that has two databases: one dealer’s database and one distributor’s database.
If you were working with both, you could keep switching between the two with use dealers, use distributors, and use dealers again, and so on.
Tip 4 # Take Instant-In-Time Backups of Servers
To take a backup of a database with journaling enabled, you can either take a file system snapshot or do a normal fsync+lock and then a dump. Note that you can’t just copy all of the files without fsync and locking, as copying is not an instantaneous operation. If the copy of the Journal files and backups reside on different volumes, then at later point in time the backups might be useless.
Tip 5 # Try to Fetch Data from a Single Query
Application unit is used as a general term for some application work. MongoDB schemas should be designed to do query per application unit.
If you have a web or a mobile application, you can think of an application unit as a request to the backend.
Some other examples:
- For a desktop application, this might be a user/client interaction.
- For an analytics system, this might be a Dashboard load.
It is basically a discrete unit of work that your application does that may involve accessing the database.
MongoDB is a fast, robust and highly scalable database. It works on many platforms and has many language drivers for its optimal usage. One of the biggest advantages of a document database is scalability through the use of embedding data. MongoDB is growing day by day and one should have clear understanding of its basics as well as tips for better usage. I hope you have learned few more tips and concepts around MongoDB. Looking forward to any queries that you may have on the topic. You can also leave a comment in the field below: