Atikh's DBA blog
  • Home
  • Oracle
  • MySQL
  • MongoDB
  • PostgreSQL
  • Snowflake
  • About Me
  • Contact Us

MongoDB : Basic Administration

 Atikh Shaikh     MongoDB     No comments   

After going through CRUD operations on MongoDB database, We will take look at some more basic MongoDB Administration

Getting MongoDB database-related information
If you want to know databases available in the system, execute "show dbs" command, it will list out all the databases

> show dbs;
admin      0.000GB
config     0.000GB
local      0.016GB
techno_db  0.001GB
> 

If you want to know in which database, you are currently execute db 
> db
techno_db
> 

if you are curious about what are the collections available under the database, just execute show collections or show tables

>show collections;
tech_large
techno_col
> 

or
> show tables;
tech_large
techno_col
> 

The command db.stats() will give you all the stats about the database 

> db.stats();
{
        "db" : "techno_db",
        "collections" : 2,
        "views" : 0,
        "objects" : 17000,
        "avgObjSize" : 37.64705882352941,
        "dataSize" : 640000,
        "storageSize" : 335872,
        "numExtents" : 0,
        "indexes" : 2,
        "indexSize" : 208896,
        "fsUsedSize" : 587198464,
        "fsTotalSize" : 10693378048,
        "ok" : 1,
        "operationTime" : Timestamp(1549877990, 1),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1549877990, 1),
                "signature" : {
                        "hash" : BinData(0,"OFOjmV2iLyqywB6fMf4bdiUZ5CU="),
                        "keyId" : NumberLong("6636938165653340162")
                }
        }
}
> 

If you want to know stats about only particular collections then that is also possible, execute db..stats() command
  
> db.techno_col.stats();
{
        "ns" : "techno_db.techno_col",
        "size" : 70000,
        "count" : 2000,
        "avgObjSize" : 35,
        "storageSize" : 86016,
        "capped" : false,
        "wiredTiger" : {
                "metadata" : {
                        "formatVersion" : 1
                },
                "creationString" :
…
…
…
},
        "nindexes" : 1,
        "totalIndexSize" : 61440,
        "indexSizes" : {
                "_id_" : 61440
        },
        "ok" : 1,
        "operationTime" : Timestamp(1549878100, 1),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1549878100, 1),
                "signature" : {
                        "hash" : BinData(0,"eBwJSS4K5vUHyZJKT54h2pduSEc="),
                        "keyId" : NumberLong("6636938165653340162")
                }
        }
}
> 

Getting Help
MongoDB provides by default build command called db.help(), it lists out commonly used methods for operating database
we can get the type command on any collections using db..help()

> db.help();
DB methods:
        db.adminCommand(nameOrDocument) - switches to 'admin' db, and runs command [just calls db.runCommand(...)]
        db.aggregate([pipeline], {options}) - performs a collectionless aggregation on this database; returns a cursor
        db.auth(username, password)
        db.cloneDatabase(fromhost) - deprecated
        db.commandHelp(name) returns the help for the command
        db.copyDatabase(fromdb, todb, fromhost) - deprecated
        db.createCollection(name, {size: ..., capped: ..., max: ...})
        db.createView(name, viewOn, [{$operator: {...}}, ...], {viewOptions})
        db.createUser(userDocument)
        db.currentOp() displays currently executing operations in the db
...
...
...
        db.shutdownServer()
        db.stats()
        db.version() current version of the server
> 
> db.techno_col.help();
DBCollection help
       db.techno_col.find().help() - show DBCursor help
       db.techno_col.bulkWrite( operations, )- ulk execute write operations, optional parameters are: w, wtimeout, j
        db.techno_col.count( query = {}, ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS
...
...
...
        db.techno_col.unsetWriteConcern( ) - unsets the write concern for writes to the collection
        db.techno_col.latencyStats() - display operation latency histograms for this collection
>  

There is one method to increase the speed of your administration by simply using the tab key on the keyboard
Just type function or procedure name and press tab, it will all available functions under it

> db.techno_col.get
db.techno_col.getCollection(        db.techno_col.getIndexSpecs(    db.techno_col.getName(             db.techno_col.getShardVersion(
db.techno_col.getDB(                db.techno_col.getIndexes(        db.techno_col.getPlanCache(         db.techno_col.getSlaveOk(
db.techno_col.getFullName(          db.techno_col.getIndices(        db.techno_col.getQueryOptions(  db.techno_col.getSplitKeysForChunks(
db.techno_col.getIndexKeys(           db.techno_col.getMongo(        db.techno_col.getShardDistribution(   db.techno_col.getWriteConcern(

To get the definition of any method can be found using not providing brackets at the time of invocation of the method
for example

> db.techno_col.getIndexes
function (filter) {
    var res = this._getIndexesCommand(filter);
    if (res) {
        return res;
    }
    return this._getIndexesSystemIndexes(filter);
}
> 

  • Share This:  
  •  Facebook
  •  Twitter
  •  Instagram
  •  Pin
  •  linkedin
  •  reddit
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Author

Atikh Shaikh
View my complete profile

Categories

  • MongoDB (18)
  • Oracle 12c (30)
  • Oracle12cR2 New Feature (3)
  • PostgreSQL (21)
  • RMAN (10)
  • Snowflake (8)
  • mysql (23)
  • oracle (74)

Blog Archive

  • ►  2018 (38)
    • ►  November (25)
    • ►  December (13)
  • ▼  2019 (33)
    • ►  January (15)
    • ▼  February (6)
      • PostgreSQL : pg_hba. conf configuration file
      • MongoDB : Creating a Large Document
      • MongoDB : Indexing and explain Plan
      • MongoDB : Basic Administration
      • Oracle : Restore points
      • Configure and Use of Flash Recovery Area
    • ►  March (2)
    • ►  April (5)
    • ►  May (5)
  • ►  2020 (5)
    • ►  April (1)
    • ►  May (2)
    • ►  July (2)
  • ►  2021 (8)
    • ►  June (3)
    • ►  July (3)
    • ►  August (1)
    • ►  December (1)
  • ►  2022 (33)
    • ►  May (3)
    • ►  June (10)
    • ►  July (3)
    • ►  August (4)
    • ►  September (8)
    • ►  October (3)
    • ►  November (2)
  • ►  2023 (14)
    • ►  February (1)
    • ►  April (5)
    • ►  May (2)
    • ►  June (1)
    • ►  September (1)
    • ►  October (1)
    • ►  December (3)
  • ►  2024 (5)
    • ►  January (2)
    • ►  March (3)
  • ►  2025 (7)
    • ►  March (1)
    • ►  April (3)
    • ►  May (2)
    • ►  August (1)
  • ►  2026 (1)
    • ►  January (1)

Popular Posts

  • PostgreSQL : pg_hba. conf configuration file
    In PostgreSQL, there are a number of configuration files, some of the files needs to be managed by postgres DBA, out of which  pg_hba.conf ...
  • User Managed Backups in Oracle
    Definition :Backup is real and consistent copy of data from database that could be used to reconstruct the data after and incident. ...
  • ORA-29283: invalid file operation: unexpected "LFI" error (1509)[29437]
    I was trying to export the schema in my windows PC, it got stuck with below error    C:\Users\shaik\Videos\technodba exp>expdp userid...
  • ORACLE : Creating a new pluggable database using PDB$SEED
    As a database administrator, you might come across creating a pluggable database, here is the method to create a pluggable database (PDB), F...
  • Oracle ASM Scrubbing
    What is ASM Scrubbing?   ASM scrubbing is a process used to identify and repair data corruption issues within an ASM disk group. ASM Scr...

Labels

oracle Oracle 12c mysql PostgreSQL MongoDB oracle 19c Oracle23c oracle19c Orale PDB-CDB oracle12c python AWS Oracle ASM Virtualbox pluggable database storage engine

Pages

  • Disclaimer
  • Privacy Policy

Follow TechnoDBA

Copyright © Atikh's DBA blog | Powered by Blogger