MongoDB Common Commands

Source: Internet
Author: User

1. Table-related commands:

Db. AddUser (username,password) Add user Db.auth (Usrename,password) Set database connection validation db.clonedatabase (fromhost) clone a database from the target server db.com MANDHELP (name) returns the Commanddb.copydatabase (fromdb,todb,fromhost) Copy database fromdb---Source database name, todb- --The target database name, fromhost---Source database server address db.createcollection (name,{size:3333,capped:333,max:88888}) to create a dataset, The equivalent of a table db.currentop () cancels the current operation of the current library db.dropdatabase () deletes the current database Db.eval (Func,args) run Co De server-sidedb.getcollection (CNAME) gets a collection of data, with the same usage: db[' CNAME '] ordb.getcollenctionnames () Gets a list of all data collection names Db.get LastError () returns the last error message Db.getlasterrorobj () returns the last Error Object Db.getmongo () Gets the connection pair for the current server Like Get the Serverdb.getmondo (). Setslaveok () Allow this connection to read from then Nonmaster membr of a replica pairdb. GetName () returns the name of the Operation database Db.getpreverror () returns the previous Error Object Db.getprofilinglevel () Gets the profile Le Veldb.getreplicationinfo () to obtain duplicate data db.gETSISTERDB (name) get the db at the same server as this onewdb.killop () stops (kills) the current operation in the current library Db.prin Tcollectionstats () returns the current library's dataset State Db.printreplicationinfo () prints the replication status information for the primary database Db.printslavereplicationinfo () print from            Replication state information for the database Db.printshardingstatus () returns whether the current database is a shared database Db.removeuser (username) Delete User db.repairdatabase () Fixed the current database Db.reseterror () Db.runcommand (cmdobj) run a database command. If Cmdobj is a string, turns it into the {Cmdobj:1}db.setprofilinglevel (level) Setting profiles level 0=off,1=slow,2=alldb.shutdow Nserver () Closes the current service program Db.version () returns the version information of the current program

2. Database-related commands:

Db.test.find ({id:10}) returns the DataSet Db.test.find ({id:10}) of the test dataset id=10. Count () returns the total number of data id=10 for the test dataset Db.test.find ({id:10}). l Imit (2) returns the dataset of the test dataset id=10 from the second data set Db.test.find ({id:10}). Skip (8) returns the DataSet id=10 the test dataset Db.test.find from 0 to eighth ({ID :). Limit (2). Skip (8) Returns the data set for the test dataset id=1= from the second to eighth Db.test.find ({id:10}). Sort () returns the test dataset id=           10 Sorted data Set Db.test.findOne ([query]) returns a data that meets the criteria Db.test.getDB () returns the database name to which this DataSet belongs Db.test.getIndexes () Returns the index information for some datasets Db.test.group ({key:...,initial:...,reduce: ...    [, cond: ...]})                      Returns the grouping information Db.test.mapReduce (mayfunction,reducefunction,<optional params>) This is a bit like a stored procedure db.test.remove (query) Delete a data set in the DataSet Db.test.renameCollection (NewName) renames the dataset name Db.test.save (obj) into the data set insert a Data Db.test.stats () returns the state of this DataSet Db.test.storageSize () returns the storage size of this dataset Db.test.totalI Ndexsize () returns the index file size of this dataset Db.test.totalSize () returns the total size of the datasets DB.TEST.UPDAte (Query,object[,upsert_bool]) updates a data db.test.validate () in this dataset to validate this DataSet db.test.getShardVersion () Returns the data set share version number

  

MongoDB Common Commands

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.