Install MongoDB

This is a step-by-step guide to install MongoDB on Mac

Pavan Kulkarni

3 minute read

This post is a step-by-step guide to install MongoDB on Mac.

About MongoDB

MongoDB is a free and open-source cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with schemas. MongoDB is developed by MongoDB Inc., and is published under a combination of the GNU Affero General Public License and the Apache License.

Main Features:

Flexible Data Model : MongoDB stores data in flexible, JSON-like documents, making it easy for you to persist and combine data of any structure. The document model maps to the objects in your application code, making data easy to work with, without giving up schema governance controls, data access, complex aggregations, and rich indexing functionality.

Distributed Data Platform : As your deployments grow in terms of data volume and throughput, MongoDB scales elastically with no downtime, and without changing your application. MongoDB lets you adapt flexibly, across data centers, with tunable consistency.

Integrated Feature Set : Analytics and data visualization, text and geospatial search, graph processing, event-driven streaming data pipelines, in-memory performance and global replication allow you to deliver a wide variety of real-time applications on one technology, reliably and securely.

Expressive query language & secondary Indexes : Indexes play a critical role in providing efficient access to data, supported natively by the database rather than maintained in application code.

Strong consistency : It is much more complex to build applications around an eventually consistent model, imposing significant work on the developer, even for the most sophisticated engineering teams

Data as Documents

MongoDB stores data in a binary representation called BSON (Binary JSON). The BSON encoding extends the popular JSON (JavaScript Object Notation) representation to include additional types such as int, long, date, floating point, and decimal128. BSON documents contain one or more fields, and each field contains a value of a specific data type, including arrays, binary data and sub-documents. MongoDB BSON documents are closely aligned to the structure of objects in the programming language. This makes it simpler and faster for developers to model how data in the application will map to data stored in the database.

Install MongoDB

  1. Open terminal and type the following Pavans-MacBook-Pro:~ pavanpkulkarni$ brew update Pavans-MacBook-Pro:~ pavanpkulkarni$ brew install mongodb
  2. Create data directory and provide required permissions

    Pavans-MacBook-Pro:~ pavanpkulkarni$ mkdir -p /data/db
    Pavans-MacBook-Pro:~ pavanpkulkarni$ chmod 775 /data/db
    
  3. Start mongo on your machine

    Pavans-MacBook-Pro:~ pavanpkulkarni$ mongod
    2018-05-15T14:46:15.957-0400 I CONTROL  [initandlisten] MongoDB starting : pid=40209 port=27017 dbpath=/data/db 64-bit host=Pavans-MacBook-Pro.local
    2018-05-15T14:46:15.958-0400 I CONTROL  [initandlisten] db version v3.6.0
    2018-05-15T14:46:15.958-0400 I CONTROL  [initandlisten] git version: a57d8e71e6998a2d0afde7edc11bd23e5661c915
    2018-05-15T14:46:15.958-0400 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2o  27 Mar 2018
    2018-05-15T14:46:15.958-0400 I CONTROL  [initandlisten] allocator: system
    2018-05-15T14:46:15.958-0400 I CONTROL  [initandlisten] modules: none
    2018-05-15T14:46:15.958-0400 I CONTROL  [initandlisten] build environment:
    2018-05-15T14:46:15.958-0400 I CONTROL  [initandlisten] distarch: x86_64
    2018-05-15T14:46:15.958-0400 I CONTROL  [initandlisten] target_arch: x86_64
    2018-05-15T14:46:15.958-0400 I CONTROL  [initandlisten] options: {}
    2018-05-15T14:46:15.958-0400 W -        [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
    2018-05-15T14:46:15.960-0400 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
    
    .
    .
    .
    .
    .
    
    2018-05-15T14:46:16.414-0400 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
    2018-05-15T14:46:16.414-0400 I CONTROL  [initandlisten]
    2018-05-15T14:46:16.437-0400 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
    2018-05-15T14:46:16.438-0400 I NETWORK  [initandlisten] waiting for connections on port 27017
    2018-05-15T14:46:17.007-0400 I FTDC     [ftdc] Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost. OK
    
    
  4. Open a new terminal and type the below to verify installation.

    Pavans-MacBook-Pro:~ pavanpkulkarni$ mongo --version
    MongoDB shell version v3.6.0
    git version: a57d8e71e6998a2d0afde7edc11bd23e5661c915
    OpenSSL version: OpenSSL 1.0.2o  27 Mar 2018
    allocator: system
    modules: none
    build environment:
        distarch: x86_64
        target_arch: x86_64
    
    

References:

  1. https://en.wikipedia.org/wiki/MongoDB
  2. https://www.mongodb.com/mongodb-architecture