Sunday 27 March 2016

Basic commands in mongodb


Lets continue with Basic commands in mongodb :


  • db : This command returns the name of connected database.

C:\Users\Nagendra>mongo
2016-03-28T21:35:56.979+0530 I CONTROL  Hotfix KB2731284 or later update is not installed, will zero-out data files
MongoDB shell version: 3.0.10
connecting to: test
>
> db
test
>


  • show databases : This command returns the list of all databases on the server.
> show databases
local  0.078GB
pcat   0.078GB
test   0.078GB


  • show collections : This command returns the list of all collections in current database.

> show collections
names
system.indexes
> 


  • use <database_name> : Used to switch between database. It will create new database if not already present.

> db
test
> use pcat
switched to db pcat
> db
pcat
> show collections
product
products
products_bak
system.indexes
> 


  • help : returns commands information

> help
        db.help()                       help on db methods
        db.mycoll.help()          help on collection methods
        sh.help()                       sharding helpers
        rs.help()                        replica set helpers
        help admin                    administrative help
        help connect                 connecting to a db help
        help keys                       key shortcuts
        help misc                       misc things to know
        help mr                          mapreduce

        show dbs                        show database names
        show collections           show collections in current database
        show users                     show users in current database
        show profile                  show most recent system.profile entries with time >= 1ms
        show logs                       show the accessible logger names
        show log [name]           prints out the last segment of log in memory, 'global' is default
        use <db_name>             set current database
        db.foo.find()                   list objects in collection foo
        db.foo.find( { a : 1 } )    list objects in foo where a == 1
        it                                       result of the last line evaluated; use to further iterate
        exit                                  quit the mongo shell
> 



What is JSON , Insert & find queries ? ...To be continued.




No comments:

Post a Comment