Useful MongoDB commands

How to install MongoDB on Mac OS X I showed already here:

If everything is installed correctly, you can start the server process as root with this command:


and the client as no root with this command:


By default you are logged in into the “test” database. You can show all dbs with this command:

show dbs

you can switch to an existing DB or create a new DB with this command:

use mynewdb

With this command here you can show alle “collections” inside of the DB:

show collections

You can make an insert with this command: { name : "myname" } )

If the collections “users” does not exist it will be created with the first call. With this command you can see all entries in the collection “users”:


With count() you can see how many elements are in the collection.


And with “remove” you can remove alle elements from a collections.


And with drop you can drop the entire collection.


Published by Robert Reiz

CEO @ VersionEye. Passionated software developer since 1998.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: