mongodb is a database based on distributed file storage. Written by the C++ language. Designed to deliver scalable, high-performance data storage solutions for WEB applications. mongodb is a product between a relational database and a non-relational database, and is the most versatile and most like relational database in a non-relational database. What is NoSQL? NoSQL, refers to a non-relational database. NoSQL, sometimes referred to as the abbreviation for Not only sql, is a generic term for a database management system that differs from a traditional relational database. NoSQL is used for storage of hyper-scale data. (for example, Google or Facebook collects trillions of bits of data for their users every day). These types of data stores do not require a fixed pattern and can be scaled horizontally without extra action. MongoDB replica set configuration because of the machine comparison card, so it is built in a virtual machine, configure the replica set, requires at least 3 instances master 192.168.1.156:27017slave 192.168.1.156:37017arbiter 192.168.1.156:47017[[email protected] _all_192.168.1.156 ~]# egrep -v ' ^#|^$ ' /etc/mongodb.conf bind_ip = 192.168.1.156port = 27017fork = truepidfilepath = /var/run/mongodb/ mongodb.pidlogpath = /var/log/mongodb/mongodb.logdbpath =/var/lib/mongodbjournal = truereplset = shard1nohttpinterface = true[[email protected]_all_192.168.1.156 ~ ]# egrep -v ' ^#|^$ ' /etc/mongodb_37017.conf bind_ip = 192.168.1.156port = 37017fork = truepidfilepath = /var/run/mongodb_37017/mongodb.pidlogpath = /var/log/mongodb_37017/ mongodb.logdbpath =/var/lib/mongodb_37017journal = truereplset = Shard1nohttpinterface = true[[email protected]_all_192.168.1.156 ~]# egrep -v ' ^#|^$ ' /etc/mongodb_47017.conf bind_ip = 192.168.1.156port = 47017fork = truepidfilepath = /var/run/mongodb_47017/mongodb.pidlogpath = /var/log/ mongodb_47017/mongodb.logdbpath =/var/lib/mongodb_47017journal = truereplset = shard1nohttpinterface = trueps aux |grep mongoroot 62095 0.6 3.1 3304700 60460 ? sl 20:07 0:24 mongod --quiet -f /etc/mongodb_57017.confroot 62387 0.6 2.0 2944248 39176 ? Sl 20:08 0:24 mongod --quiet -f /etc/mongodb_47017.confroot 66145 0.6 3.5 5419352 67156 ? Sl 20:20 0:18 mongod --quiet -f /etc/mongodb_37017.confroot 68910 0.6 3.1 5264784 60024 ? sl 20:25 0:16 mongod --quiet -f /etc/mongodb.conf[[email protected]_all_192.168.1.156 ~]# mongo --host=192.168.1.156MongoDB shell version: 2.4.14connecting to: 192.168.1.156:27017/testshard1:pRimary> show dbs;local2.0771484375gbtest0.203125gbwabao0.203125gbshard1:primary>rs.conf () {"_id " : " Shard1 "," Version " : 15," members " : [{" _id " : 0," host "&NBSP;: "192.168.1.156:27017", "Priority" : 10},{"_id" : 1, "host" : " 192.168.1.156:37017 "," Priority " : 5},{" _id " : 2," host " : " 192.168.1.156:57017 "," Priority " : 3}]} shard1:primary>rs.conf () shard1:primary> helpdb.help () help on db methodsdb.mycoll.help () help on collection methodssh.help () sharding Helpersrs.help () replica set helpershelp admin administrative helphelp connect connecting to a db helphelp keys key shortcutshelp misc misc things to knowhelp mr mapreduceshow dbs show database namesshow collections show collections in current databaseshow users show users in current databaseshow profile show most recent system.profile entries with time >= 1msshow logs show the accessible logger namesshow log [name] prints out the last segment of log in memory, ' Global ' is defaultuse <db_name> set current databasedb.foo.find () list objects in collection foodb.foo.find ( { a : 1 } ) list objects in foo where a == 1it result of the last line evaluated; use to further iterateDBQuery.shellBatchSize = x set default number of items to display on shellexit &nbSp; quit the mongo shellshard1: Primary> db.help () Db methods:db.adduser (userdocument) Db.admincommand (nameOrDocument) - switches to ' admin ' db, and runs command [ just calls Db.runcommand (...) ]db.auth (Username, password) db.clonedatabase (fromhost) db.commandhelp (name) returns the help for the commanddb.copydatabase (fromdb, todb, fromhost) db.createCollection ( name, { size : ..., capped : ..., max : ... } ) Db.currentop () displays currently executing operations in the Dbdb.dropdatabase () db.eval (Func, args) run code server-sidedb.fsynclock () flush Data to disk and lock server for backupsdb.fsyncunlock () unlocks server following&Nbsp;a db.fsynclock () db.getcollection (CNAME) same as db[' CNAME '] or Db.cnamedb.getCollectionNames () db.getlasterror () - just returns the err msg stringdb.getlasterrorobj () - return full status objectdb.getmongo () get the server connection objectdb.getmongo (). Setslaveok () allow queries on a replication slave serverdb.getname () Db.getpreverror () Db.getprofilinglevel () - deprecateddb.getprofilingstatus () - returns if profiling is on and slow thresholddb.getreplicationinfo () db.getsiblingdb (name) get the db at The same server as this onedb.hostinfo () get details about the server ' S hostdb.ismaster () check replica primary statusdb.killop (opid) kills the current operation In the dbdb.listcommands () lists all the db commandsdb.loadserverscripts () loads all the scripts in db.system.jsdb.logout () Db.printCollectionStats () Db.printreplicationinfo () Db.printshardingstatus () Db.printslavereplicationinfo () Db.removeuser (username) Db.repairdatabase () Db.reseterror () Db.runcommand (cmdobj) run a database command. if cmdobj is a string, turns it into { cmdobj : 1 }db.serverstatus () db.setprofilinglevel (level,<slowms>) 0=off 1=slow 2= Alldb.setverboseshell (flag) display extra information in shell Outputdb.shutdownserver () db.stats () db.version () current version of the servershard1: Primary> rs.help () rs.status () { rEplsetgetstatus : 1 } checks repl set statusrs.initiate () { replsetinitiate : null } initiates set with default Settingsrs.initiate (CFG) { replsetinitiate : cfg } initiates set with configuration cfgrs.conf () get the current configuration object From local.system.replsetrs.reconfig (CFG) updates the configuration of a running replica set with cfg (Disconnects) Rs.add (HOSTPORTSTR) add a new member to the set with default attributes ( Disconnects) Rs.add (membercfgobj) add a new member to the set with extra attributes (Disconnects) Rs.addarb (HOSTPORTSTR) add a new member which is arbiteronly:true (disconnects) Rs.stepdown ([secs]) step down as primary (momentarily) (disconnects) Rs.syncfrom (HOSTPORTSTR) make a Secondary to sync from the given memberrs.freeze (secs) make a node ineligible to become Primary for the time specifiedrs.remove (HOSTPORTSTR) remove a host from the replica set (Disconnects) Rs.slaveok () shorthand for db.getmongo (). Setslaveok () Db.ismaster () check who is primarydb.printreplicationinfo () check oplog size and time rangereconfiguration helpers disconnect from the database so the shell will displayan error, even if the Command succeeds.see also&nbsP;http://<mongod_host>:28017/_replset for additional diagnostic infoshard1:primary > db.collection.find (). Help () Find () modifiers.sort ( {...} ). Limit ( n ). Skip ( n ). Count () - total # of objects Matching query, ignores skip,limit.size () - total # of objects Cursor would return, honors skip,limit.explain ([verbose]). Hint (...). AddOption (n) - adds op_query options -- see wire protocol._addspecial ( Name, value) - http://dochub.mongodb.org/core/advancedqueries# Advancedqueries-metaqueryoperators.batchsize (n) - sets the number of docs To return per getmore.showdiskloc () - adds a $diskLoc field to each returned object.min (Idxdoc). Max (Idxdoc) Cursor methods.toarray () - iterates through docs and returns an array of the results.foreach ( func ). Map ( func ). Hasnext (). Next (). Objsleftinbatch () - returns count of docs left in current batch (When exhausted, a new getmore will be issued). Count (Applyskiplimit) - runs command at Server.itcount () - iterates through documents and counts themshard1:primary > sh.help () Sh.addshard ( host ) server:port or setname /server:portsh.enablesharding (dbname) enables sharding on the database Dbnamesh.shardcollection (Fullname,key,unique) &NBSP;&NBSp; shards the collectionsh.splitfind (Fullname,find) splits the chunk that find is in at the mediansh.splitat (Fullname,middle) splits the chunk that middle is in at middlesh.movechunk (fullname,find,to) move the chunk where ' find ' is to ' to ' (Name of shard) Sh.setbalancerstate ( <bool on or not> ) turns the Balancer on or off true=on, false=offsh.getbalancerstate () return true if&nbsP;enabledsh.isbalancerrunning () return true if the balancer has work in progress on any mongossh.addshardtag (Shard,tag) adds the tag to The shardsh.removeshardtag (Shard,tag) removes the tag from the shardsh.addtagrange (FullName,min,max,tag) tags the specified range of the given Collectionsh.status ()
This article is from the "tireless learning ..." Blog, be sure to keep this source http://jonyisme.blog.51cto.com/3690784/1902331
MongoDB Learning (-)