MONGODB command queries all database lists

Source: Internet
Author: User
Tags mongodb table name
MONGODB command queries all database lists

CODE:

> Show DBS

If you want to see which database the current connection is under, you can enter the DB directly
CODE:

> DB
Admin
Want to switch to the test database below
CODE:

> Use test
Switched to DB test
> DB
Test
To see what tables or collection are under test, you can enter
CODE:

> Show Collections
System.indexes
User
If you want to know which commands MongoDB supports, you can enter help directly
CODE:
> Help
DOS Codes    help         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          use <d b name>                 set curent database to <db name>          db.help ()                      help on DB methods          db.foo.help ()                  help on collection methods          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   If you want to know which methods are supported by the current database: 
CODE:

> Db.help ();
Java Code    db methods:         db.adduser (username,  Password)   Add database authorized users          db.auth (Username, password)                   Access Certifications          db.clonedatabase (fromhost)   Clone database           db.commandhelp (name)  returns the help for the command         db.copydatabase (fromdb, todb, fromhost)    Copy Database           db.createcollection (name, { size : ...,  capped : ..., max : ... } )   CREATE TABLE           db.currentop ()  displays the current operation in the db    &NBSP;&NBSP;&NBsp;   db.dropdatabase ()          Delete current database          db.eval_r (Func, args)  run code server-side         db.getcollection (CNAME)  same as db[' CNAME '] or  db.cname         db.getcollectionnames ()           get the table name of the current database          db.getlasterror ()  - just  returns the err msg string          Db.getlasterrorobj ()  - return full status object          db.getmongo ()  get the server connection object          db.getmongo (). Setslaveok ()  allow this connection to read  from the nonmaster member of a replica pair          Db.getname ()          db.getpreverror ()           db.getprofilinglevel ()          db.getreplicationinfo ( )          db.getsisterdb (name)  get the db at  the same server as this onew         db.killop ()  kills the current operation in the db          db.printcollectionstats ()     print status information for each table           db.printreplicationinfo ()          Print replication status information for the primary database          db.printslavereplicationinfo ()           Print replication status information from the database          db.printshardingstatus ()                   Print Shard status information           Db.removeuser (username)   Delete database user          db.repairdatabase ()   Repair Database          db.reseterror ()           db.runcommand (cmdobj)  run a database command.  if cmdobj is  a string, turns it into { cmdObj : 1 }          db.setprofilinglevel (level)  0=off 1=slow 2=all          db.shutdownserver ()          db.version ()  current version of the server  
If you want to know which methods are supported by the table or table collection under the current database, you can use commands such as:
CODE:

> Db.user.help (); User is the table name
Java Code    dbcollection help         db.foo.count ()   Number of rows for                 statistics          db.foo.datasize ()          Statistical data size          db.foo.distinct ( key )  - eg.  Db.foo.distinct (  ' x '  )                   Remove Weight          db.foo.drop ()  drop the by given conditions  collection  Delete Table          db.foo.dropindex (name)    Delete specified index          db.foo.dropindexes ()   Delete all indexes           db.foo.ensureindex (keypattern,options)  - options should be an  object with these possible fields: name, unique, dropdups   Add index          db.foo.find ( [query] , [fields])  - first  parameter is an optional query filter. second parameter is  optional set of fields to return.   
Finding data based on criteria
-----------------------
Query by Condition: Db.foo.find ({x:77}, {name:1, x:1})
-----------------------------
Db.foo.find (...). Count ()
Db.foo.find (...). Limit (n) finds data based on criteria and returns the specified number of records
Db.foo.find (...). Skip (N)
Db.foo.find (...). Sort (...) Find sorting
Db.foo.findOne ([query]) query only one piece of data based on a conditional query
Db.foo.getDB () Get DB object associated with collection returns the library to which the table belongs
Db.foo.getIndexes () Displays all indexes of the table
Db.foo.group ({key: ..., initial: ..., reduce: ...) [, cond: ...] }) grouped by criteria
Db.foo.mapReduce (Mapfunction, reducefunction, <optional params>)
Db.foo.remove (query) to delete data based on criteria
Db.foo.renameCollection (NewName) renames the collection rename table
Db.foo.save (obj) saving data
Db.foo.stats () View the status of a table
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.