DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Data Engineering
  3. Databases
  4. Get MongoDB Up and Running on Your Mac

Get MongoDB Up and Running on Your Mac

Andy Hawthorne user avatar by
Andy Hawthorne
·
Feb. 29, 12 · Interview
Like (0)
Save
Tweet
Share
9.93K Views

Join the DZone community and get the full member experience.

Join For Free

MongoDB is a document oriented, NoSQL database. It is gathering momentum and popularity amongst developers because it is flexible, and scalable at the same time. In this article I will describe how I got it set up and working on my Mac running OS X 10.7.3 and MAMP with PHP 5.2.17, and PHP 5.3.6.

What is MongoDB?

MongoDB is an open source application written in the C++ programming language. It is a NoSQL data storage type database, meaning that it stores data in collections. The collections consist of a set of documents. Documents contain a set of key-value pairs, and don’t have to be defined before you start using the database.

Installing MongoDB

You don’t actually install MongoDB, not really. You can download the precompiled binaries, place the resulting directory somewhere (I chose my home folder), and it is nearly ready to begin. I chose version 2.0.2 and the 64-bit OS X option, and that is what this article is based on.

You need to create a data directory. There is advice on the MongoDB web site how to do that, so that is pretty much what I did:

$ sudo mkdir -p /data/db/
$ sudo chown `id -u` /data/db

Does it work?

Now we can check to see if things are working. Open up the terminal app, change directory into your home folder if you are not there already:

$ cd ~/

I renamed the Mongo folder to just mongodb to make it easier to type. Then you can start the server:

$ ./mongodb/bin/mongod

Then, in a new terminal tab connect to localhost:

$ ./mongodb/bin/mongo

That should return something like this:

MongoDB shell version: 2.0.2
connecting to: test
>

 We are in “it just works” territory here. I have gone through these steps on several Macs now, and it does indeed just work. We’ll tell Mongo that we want to use a particular collection (these commands should be typed in the localhost shell window):

> use testingdb

Mongo will reply that it has switched to the db called testingdb. Next, we will add some data:

> db.testingdb.insert({title: "a test note", note: "This is my first note", 
  tags: "Testing"})

Here, you can see that I have defined 3 fields: title, note, and tags.When you hit enter, the record will be saved. Add some more, in the same way and then we can query the collection to see our records:

> db.testingdb.find()

 

This command will return all the results found in the collection. It also demonstrates that things are working nicely. Now for some drivers.

Installing the PHP Drivers in MAMP

First, you need to visit Github and download the driver version for PHP that you use most commonly with MAMP. There is a binary build for both PHP 5.2 and PHP 5.3 available.

You will then need to move the downloaded binary (mongo.so) into the correct folder for MAMP to find it. The folder can be found at: /applications/MAMP/bin/php/php5.2.17/lib/php/extensions/no-debug-non-zts-20060613

I’m running MAMP 2.0.3, but it should be something similar for other version too. Next, we will need to edit the PHP.ini template in MAMP. From the menu bar:

editing the MAMP PHP.ini template

Once in there (you can click OK on the warning message), scroll to the extensions section and add the reference to mongo.so:

editing the MAMP PHP.ini template

Save, and the re-start MAMP. If you then go to web start and click phpInfo, you should be able to scroll down and see:

Mongo up and running in MAMP

That means you are now ready to start coding with MongoDB and MAMP.

Finally…

This is a quick and easy way to get up and running with MongoDB on OS X Lion running MAMP. There are other installation methods, such as installing via Homebrew, but so far, I have found this to work perfectly.

Because this is experimental to some extent though, please share your experiences below.


MongoDB

Published at DZone with permission of Andy Hawthorne, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Cloud Performance Engineering
  • Reliability Is Slowing You Down
  • Building a Real-Time App With Spring Boot, Cassandra, Pulsar, React, and Hilla
  • gRPC on the Client Side

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: