Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
MongoDB Cookbook - Second Edition

You're reading from   MongoDB Cookbook - Second Edition Modern Database Management Made Easy

Arrow left icon
Product type Paperback
Published in Jan 2016
Publisher
ISBN-13 9781785289989
Length 370 pages
Edition 2nd Edition
Tools
Arrow right icon
Authors (2):
Arrow left icon
Amol Nayak Amol Nayak
Author Profile Icon Amol Nayak
Amol Nayak
Cyrus Dasadia Cyrus Dasadia
Author Profile Icon Cyrus Dasadia
Cyrus Dasadia
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Installing and Starting the Server 2. Command-line Operations and Indexes FREE CHAPTER 3. Programming Language Drivers 4. Administration 5. Advanced Operations 6. Monitoring and Backups 7. Deploying MongoDB on the Cloud 8. Integration with Hadoop 9. Open Source and Proprietary Tools A. Concepts for Reference Index

Single node installation of MongoDB with options from the config file

As we can see, providing options from the command line does the work, but it starts getting awkward as soon as the number of options that we provide increase. We have a nice and clean alternative to provide the start up options from a configuration file rather than as command-line arguments.

Getting ready

If you have already executed the Installing single node MongoDB recipe, you need not do anything different as all the prerequisites of this recipe are the same.

How to do it…

The /data/mongo/db directory for the database and /logs/ for the logs should be created and present on your filesystem with the appropriate permissions to write to it and perform the following steps:

  1. Create a configuration file that can have any arbitrary name. In our case, let's say that we create this in /conf/mongo.conf. We then edit the file and add the following lines to it:
    port = 27000
    dbpath = /data/mongo/db
    logpath = /logs/mongo.log
    smallfiles = true
  2. Start the mongo server using the following command:
    > mongod --config  /config/mongo.conf
    

How it works…

All the command-line options that we discussed in the previous recipe, Starting a single node instance using command-line options, hold true. We are just providing them in a configuration file instead. If you have not visited the previous recipe, I would recommend you to do so as that is where we discussed some of the common command-line options. The properties are specified as <property name> = <value>. For all the properties that don't have values, for example, the smallfiles option, the value given is a Boolean value, true. If we need to have a verbose output, we would add v=true (or multiple v's to make it more verbose) to our configuration file. If you already know what the command-line option is, then it is pretty easy to guess what the value of the property is in the file. It is almost the same as the command-line option with just the hyphen removed.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image