Skip to content

1.MongoDB Basics

How to Connect:

SQL
mongo -u mongoadmin -p 4dminPassw0rd --authenticationDatabase admin mongodb://tempdb1,tempdb2,tempdb3/readPreference=primaryPreferred
or

SQL
mongo "mongodb://user_name:[email protected]/db_name?authSource=admin"

Create db mydb:

SQL
use mydb
Text Output
> use mydb
switched to db mydb

Create a collection mycollection:

SQL
db.createCollection("mycollection")

Show dbs

SQL
show dbs;
SQL
somedb-replica:PRIMARY> show dbs;
somedb_integration            0.002GB
duptrans_go                   0.030GB
other_integration             0.050GB
db_public                     0.150GB

Drop database

SQL
use integration;
SQL
db.dropDatabase();
SQL
durbok-replica:PRIMARY> db.dropDatabase()
{
        "dropped" : "integration",
        "ok" : 1,
        "$clusterTime" : {
                "clusterTime" : Timestamp(1669033752, 15),
                "signature" : {
                        "hash" : BinData(0,"zT9H9L7Z2lwO5ogZfubTRqJQvxQ="),
                        "keyId" : NumberLong("7152889516020203523")
                }
        },
        "operationTime" : Timestamp(1669033752, 15)
}
Back to top