|
| 1 | +mongod --help |
| 2 | + |
| 3 | +> help |
| 4 | + db.help() help on db methods |
| 5 | + db.mycoll.help() help on collection methods |
| 6 | + sh.help() sharding helpers |
| 7 | + rs.help() replica set helpers |
| 8 | + help admin administrative help |
| 9 | + help connect connecting to a db help |
| 10 | + help keys key shortcuts |
| 11 | + help misc misc things to know |
| 12 | + help mr mapreduce |
| 13 | + |
| 14 | + show dbs show database names |
| 15 | + show collections show collections in current database |
| 16 | + show users show users in current database |
| 17 | + show profile show most recent system.profile entries with time >= 1ms |
| 18 | + show logs show the accessible logger names |
| 19 | + show log [name] prints out the last segment of log in memory, 'global' is default |
| 20 | + use <db_name> set current database |
| 21 | + db.foo.find() list objects in collection foo |
| 22 | + db.foo.find( { a : 1 } ) list objects in foo where a == 1 |
| 23 | + it result of the last line evaluated; use to further iterate |
| 24 | + DBQuery.shellBatchSize = x set default number of items to display on shell |
| 25 | + exit quit the mongo shell |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +> use shop |
| 30 | +switched to db shop |
| 31 | +> db.help() |
| 32 | +DB methods: |
| 33 | + db.adminCommand(nameOrDocument) - switches to 'admin' db, and runs command [just calls db.runCommand(...)] |
| 34 | + db.aggregate([pipeline], {options}) - performs a collectionless aggregation on this database; returns a cursor |
| 35 | + db.auth(username, password) |
| 36 | + db.cloneDatabase(fromhost) |
| 37 | + db.commandHelp(name) returns the help for the command |
| 38 | + db.copyDatabase(fromdb, todb, fromhost) |
| 39 | + db.createCollection(name, {size: ..., capped: ..., max: ...}) |
| 40 | + db.createView(name, viewOn, [{$operator: {...}}, ...], {viewOptions}) |
| 41 | + db.createUser(userDocument) |
| 42 | + db.currentOp() displays currently executing operations in the db |
| 43 | + db.dropDatabase() |
| 44 | + db.eval() - deprecated |
| 45 | + db.fsyncLock() flush data to disk and lock server for backups |
| 46 | + db.fsyncUnlock() unlocks server following a db.fsyncLock() |
| 47 | + db.getCollection(cname) same as db['cname'] or db.cname |
| 48 | + db.getCollectionInfos([filter]) - returns a list that contains the names and options of the db's collections |
| 49 | + db.getCollectionNames() |
| 50 | + db.getLastError() - just returns the err msg string |
| 51 | + db.getLastErrorObj() - return full status object |
| 52 | + db.getLogComponents() |
| 53 | + db.getMongo() get the server connection object |
| 54 | + db.getMongo().setSlaveOk() allow queries on a replication slave server |
| 55 | + db.getName() |
| 56 | + db.getPrevError() |
| 57 | + db.getProfilingLevel() - deprecated |
| 58 | + db.getProfilingStatus() - returns if profiling is on and slow threshold |
| 59 | + db.getReplicationInfo() |
| 60 | + db.getSiblingDB(name) get the db at the same server as this one |
| 61 | + db.getWriteConcern() - returns the write concern used for any operations on this db, inherited from server object if set |
| 62 | + db.hostInfo() get details about the server's host |
| 63 | + db.isMaster() check replica primary status |
| 64 | + db.killOp(opid) kills the current operation in the db |
| 65 | + db.listCommands() lists all the db commands |
| 66 | + db.loadServerScripts() loads all the scripts in db.system.js |
| 67 | + db.logout() |
| 68 | + db.printCollectionStats() |
| 69 | + db.printReplicationInfo() |
| 70 | + db.printShardingStatus() |
| 71 | + db.printSlaveReplicationInfo() |
| 72 | + db.dropUser(username) |
| 73 | + db.repairDatabase() |
| 74 | + db.resetError() |
| 75 | + db.runCommand(cmdObj) run a database command. if cmdObj is a string, turns it into {cmdObj: 1} |
| 76 | + db.serverStatus() |
| 77 | + db.setLogLevel(level,<component>) |
| 78 | + db.setProfilingLevel(level,slowms) 0=off 1=slow 2=all |
| 79 | + db.setWriteConcern(<write concern doc>) - sets the write concern for writes to the db |
| 80 | + db.unsetWriteConcern(<write concern doc>) - unsets the write concern for writes to the db |
| 81 | + db.setVerboseShell(flag) display extra information in shell output |
| 82 | + db.shutdownServer() |
| 83 | + db.stats() |
| 84 | + db.version() current version of the server |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | +> show collections |
| 90 | +products |
| 91 | +> db.products.help() |
| 92 | +DBCollection help |
| 93 | + db.products.find().help() - show DBCursor help |
| 94 | + db.products.bulkWrite( operations, <optional params> ) - bulk execute write operations, optional parameters are: w, wtimeout, j |
| 95 | + db.products.count( query = {}, <optional params> ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS |
| 96 | + db.products.copyTo(newColl) - duplicates collection by copying all documents to newColl; no indexes are copied. |
| 97 | + db.products.convertToCapped(maxBytes) - calls {convertToCapped:'products', size:maxBytes}} command |
| 98 | + db.products.createIndex(keypattern[,options]) |
| 99 | + db.products.createIndexes([keypatterns], <options>) |
| 100 | + db.products.dataSize() |
| 101 | + db.products.deleteOne( filter, <optional params> ) - delete first matching document, optional parameters are: w, wtimeout, j |
| 102 | + db.products.deleteMany( filter, <optional params> ) - delete all matching documents, optional parameters are: w, wtimeout, j |
| 103 | + db.products.distinct( key, query, <optional params> ) - e.g. db.products.distinct( 'x' ), optional parameters are: maxTimeMS |
| 104 | + db.products.drop() drop the collection |
| 105 | + db.products.dropIndex(index) - e.g. db.products.dropIndex( "indexName" ) or db.products.dropIndex( { "indexKey" : 1 } ) |
| 106 | + db.products.dropIndexes() |
| 107 | + db.products.ensureIndex(keypattern[,options]) - DEPRECATED, use createIndex() instead |
| 108 | + db.products.explain().help() - show explain help |
| 109 | + db.products.reIndex() |
| 110 | + db.products.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return. |
| 111 | + e.g. db.products.find( {x:77} , {name:1, x:1} ) |
| 112 | + db.products.find(...).count() |
| 113 | + db.products.find(...).limit(n) |
| 114 | + db.products.find(...).skip(n) |
| 115 | + db.products.find(...).sort(...) |
| 116 | + db.products.findOne([query], [fields], [options], [readConcern]) |
| 117 | + db.products.findOneAndDelete( filter, <optional params> ) - delete first matching document, optional parameters are: projection, sort, maxTimeMS |
| 118 | + db.products.findOneAndReplace( filter, replacement, <optional params> ) - replace first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument |
| 119 | + db.products.findOneAndUpdate( filter, update, <optional params> ) - update first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument |
| 120 | + db.products.getDB() get DB object associated with collection |
| 121 | + db.products.getPlanCache() get query plan cache associated with collection |
| 122 | + db.products.getIndexes() |
| 123 | + db.products.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } ) |
| 124 | + db.products.insert(obj) |
| 125 | + db.products.insertOne( obj, <optional params> ) - insert a document, optional parameters are: w, wtimeout, j |
| 126 | + db.products.insertMany( [objects], <optional params> ) - insert multiple documents, optional parameters are: w, wtimeout, j |
| 127 | + db.products.mapReduce( mapFunction , reduceFunction , <optional params> ) |
| 128 | + db.products.aggregate( [pipeline], <optional params> ) - performs an aggregation on a collection; returns a cursor |
| 129 | + db.products.remove(query) |
| 130 | + db.products.replaceOne( filter, replacement, <optional params> ) - replace the first matching document, optional parameters are: upsert, w, wtimeout, j |
| 131 | + db.products.renameCollection( newName , <dropTarget> ) renames the collection. |
| 132 | + db.products.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection name |
| 133 | + db.products.save(obj) |
| 134 | + db.products.stats({scale: N, indexDetails: true/false, indexDetailsKey: <index key>, indexDetailsName: <index name>}) |
| 135 | + db.products.storageSize() - includes free space allocated to this collection |
| 136 | + db.products.totalIndexSize() - size in bytes of all the indexes |
| 137 | + db.products.totalSize() - storage allocated for all data and indexes |
| 138 | + db.products.update( query, object[, upsert_bool, multi_bool] ) - instead of two flags, you can pass an object with fields: upsert, multi |
| 139 | + db.products.updateOne( filter, update, <optional params> ) - update the first matching document, optional parameters are: upsert, w, wtimeout, j |
| 140 | + db.products.updateMany( filter, update, <optional params> ) - update all matching documents, optional parameters are: upsert, w, wtimeout, j |
| 141 | + db.products.validate( <full> ) - SLOW |
| 142 | + db.products.getShardVersion() - only for use with sharding |
| 143 | + db.products.getShardDistribution() - prints statistics about data distribution in the cluster |
| 144 | + db.products.getSplitKeysForChunks( <maxChunkSize> ) - calculates split points over all chunks and returns splitter function |
| 145 | + db.products.getWriteConcern() - returns the write concern used for any operations on this collection, inherited from server/db if set |
| 146 | + db.products.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the collection |
| 147 | + db.products.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the collection |
| 148 | + db.products.latencyStats() - display operation latency histograms for this collection |
0 commit comments