Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

6.mongo Command prompt help

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

6.mongo Command prompt help

The latest content will be updated at the origin server. To reprint, please keep the original link: http://dashidan.com/article/mongodb/index.html

① mongo Command Line Parameter help

Display command line help information through the-- help parameter

Mongo-help

Display:

MongoDB shell version: 2.0.4usage: mongo [options] [db address] [file names (ending in .js)] db address can be: foo foo database on local machine 192.169.0.5/foo foo database on 192.168.0.5 machine 192.169.0.5:9999/foo foo database on 192.168.0.5 machine on port 9999options:-- shell run the shell after executing files-- Nodb don't connect to mongod on startup-no'db address' arg expected-- norc starts not executing the ".mongorc.js" file-- quiet quiet mode-- port arg port-- host arg IP-- eval arg runs the javascript script-u [ -- username] arg user name-p [--password] arg password-h [--help] displays this help-- version version number-- verbose increase verbosity-- ipv6 enables IPv6 support (off by default)

② mongo instruction help

After connecting to the mongo database from the command prompt, you can enter help to display command prompt help.

Help

The following is displayed:

Db.help () database method help information db.mycoll.help () collection method help information rs.help () help on replica set methodshelp admin administrator help information help connect connection database help help keys shortcut key help misc Miscellaneous information help help mr mapreduce help show dbs display all database names show collections display all collection names in the current database show users display all users in the current database show profile show most recent system.profile entries with time > = 1msshow logs Displays the log (`logger`) name show log [name] that can be connected to the output memory of the most recent log fragment Default output `global`use sets the current database db.foo.find () displays the list of objects in the collection `foo` db.foo.find ({a: 1}) queries the it input it of the objects `a = = 1` in the foo collection, and continues to iteratively display the results Output more results DBQuery.shellBatchSize = x set the number of display results exit exits the command line

③ Database help

1. Show all databases show dbs2. Display unit data operation help db.help () 3. Realization of display method

Display a data of the specific implementation of the method, input db. Without (). For example:

Db.updateUser

Display:

Test.updateUser

④ Collection help

1. Show all collections show collections2. Show collection help db.collection.help ()

Display

Db.collection.find (). Help ()-show DBCursor helpdb.collection.count () db.collection.dataSize () db.collection.distinct (key)-eg. Db.collection.distinct ('x') db.collection.drop () drop the collectiondb.collection.dropIndex (name) db.collection.dropIndexes () db.collection.ensureIndex (keypattern [, options])-options is an object with these possible fields: name, unique, dropDupsdb.collection.reIndex () db.collection.find ([query], [fields])-query is an optional query filter. Fields is optional set of fields to return. E.g. Db.collection.find ({name:1, x db.collection.find 1}) db.collection.find (.). Count () db.collection.find (.). Limit (n) db.collection.find (.). Skip (n) db.collection.find (.). Sort (...) db.collection.findOne ([query]) db.collection.findAndModify ({update:..., remove: bool [, query: {}) Sort: {}, 'new': false]}) db.collection.getDB () getDB object associated with collectiondb.collection.getIndexes () db.collection.group ({key:..., initial:..., reduce:... [, cond:...]}) db.collection.mapReduce (mapFunction, reduceFunction,) db.collection.remove (query) db.collection.renameCollection (newName,) renames the collection.db.collection.runCommand (name ) runs a db command with the given name where the first param is the collection namedb.collection.save (obj) db.collection.stats () db.collection.storageSize ()-includes free space allocated to this collectiondb.collection.totalIndexSize ()-size in bytes of all the indexesdb.collection.totalSize ()-storage allocated for all data and indexesdb.collection.update (query, object [, upsert_bool) Multi_bool) db.collection.validate ()-SLOWdb.collection.getShardVersion ()-only for use with shardingdb.collection.getShardDistribution ()-prints statistics about data distribution in the cluster3. Implementation of display set method

The display method implements the input db.., without (). For example, enter:

Db.collection.save

Display:

Function (obj) {if (obj = = null | | typeof obj = = "undefined") {throw "can't save a null";} if (typeof obj = = "number" | | typeof obj = = "string") {throw "can't save a number or string";} if (typeof obj._id = = "undefined") {obj._id = new ObjectId; return this.insert (obj) } else {return this.update ({_ id:obj._id}, obj, true);}}

⑤ cursor help

When you use the find () method on the mongo command line, you can use many cursor methods to modify the find () behavior and results.

Displays the modifiers and cursor handling methods available to the find () method

Db.collection.find () .help ()

Display:

> 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 (...) .showDiskLoc ()-adds a $diskLoc field to each returned objectCursor methods .forEach (func) .map (func) .hasNext () .next ()

To see the implementation of the cursor method, enter db..find (). Does not include (). For example:

Db.collection.find () toArray

Display:

> db.collection.find () .toArrayfunction () {if (this._arr) {return this._arr;} var a = []; while (this.hasNext ()) {a.push (this.next ());} this._arr = a; return a;}

Commonly used cursor methods

HasNext () queries whether cursor has any more data.

Next () returns the next data object, and cursor points to the location plus 1. 0.

ForEach (

Method traverses and executes all the results. There is only 1 parameter, the object pointed to in the iterator.

⑥ wrapper object help

You can get the object wrapper class by typing help misc.

Help misc

Display:

> help misc b = new BinData (subtype Base64str) create a BSON BinData value b.subtype () the BinData subtype (0.255) b.length () length of the BinData data in bytes b.hex () the data as a hex encoded string b.base64 () the data as a base64 encoded string b.toString () b = HexData (subtype Hexstr) create a BSON BinData value from a hex string b = UUID (hexstr) create a BSON BinData value of UUID subtype b = MD5 (hexstr) create a BSON BinData value of MD5 subtype o = new ObjectId () create a new ObjectId o.getTimestamp () return timestamp derived from first 32 bits of the OID o.isObjectId () o.toString () o.equals (otherid)

⑦ reference articles

Official document

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report