Skip to content
This repository was archived by the owner on Feb 7, 2022. It is now read-only.

MongoDB useful commands

Pablo edited this page Feb 26, 2018 · 2 revisions

Introduction

This is a handfull of commands or scripts that make easy to use the mongo console. The intend of this wiki page is to help anyone out there who is using mongodb for the first time and its a bit lost like me. Please consider that this is not a usage manual but only some notes or clarifications I would like to made about using mongoDB ##Basics The most inportant command is help. This will fire all the documentation within the commandline, is the first source of information you should check.

help

There is also

db.help() 

and

db.mycoll.help()

For collections and the very own database.

Deleting all databases

This script is pasted on the mongo console and will REMOVE ALL your databases in the host. Very useful to clean everything after testing.

var dbs = db.getMongo().getDBNames()
for(var i in dbs){
    db = db.getMongo().getDB( dbs[i] );
    print( "dropping db " + db.getName() );
    db.dropDatabase();
}

Return home

Reference: StackOverflow

Clone this wiki locally