当登入到mongoDB 之后 可以使用help 命令查看帮助文档
系统级帮助文档
> help
db.help() help on db methods # 数据库级别帮助文档
db.mycoll.help() help on collection methods # 集合级别帮助文档
sh.help() sharding helpers # 关于分片的帮助文档
rs.help() replica set helpers
help admin administrative help # 管理员帮助文档
help connect connecting to a db help # 连接数据库帮助文档
help keys key shortcuts
help misc misc things to know
help mr mapreduce
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 # 显示profile
show logs show the accessible logger names # 显示日志(只是显示有哪些日志)
show log [name] prints out the last segment of log in memory, ‘global‘ is default # 显示指定日志的内容
use <db_name> set current database # 切换到指定数据库,如果不存在则默认创建
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
DBQuery.shellBatchSize = x set default number of items to display on shell
exit quit the mongo shell
>
数据库级别帮助文档 使用db.数据库名称.help()
例如:
> db.mymongo.help()
DBCollection help
db.mymongo.find().help() - show DBCursor help # 查询 帮助文档
db.mymongo.bulkWrite( operations, <optional params> ) - bulk execute write operations, optional parameters are: w, wtimeout, j
db.mymongo.count( query = {}, <optional params> ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS
db.mymongo.copyTo(newColl) - duplicates collection by copying all documents to newColl; no indexes are copied.
db.mymongo.convertToCapped(maxBytes) - calls {convertToCapped:‘mymongo‘, size:maxBytes}} command
db.mymongo.createIndex(keypattern[,options])
db.mymongo.createIndexes([keypatterns], <options>)
db.mymongo.dataSize()
db.mymongo.deleteOne( filter, <optional params> ) - delete first matching document, optional parameters are: w, wtimeout, j
db.mymongo.deleteMany( filter, <optional params> ) - delete all matching documents, optional parameters are: w, wtimeout, j
db.mymongo.distinct( key, query, <optional params> ) - e.g. db.mymongo.distinct( ‘x‘ ), optional parameters are: maxTimeMS
db.mymongo.drop() drop the collection
db.mymongo.dropIndex(index) - e.g. db.mymongo.dropIndex( "indexName" ) or db.mymongo.dropIndex( { "indexKey" : 1 } )
db.mymongo.dropIndexes()
db.mymongo.ensureIndex(keypattern[,options]) - DEPRECATED, use createIndex() instead
db.mymongo.explain().help() - show explain help
db.mymongo.reIndex()
db.mymongo.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return.
e.g. db.mymongo.find( {x:77} , {name:1, x:1} )
db.mymongo.find(...).count()
db.mymongo.find(...).limit(n)
db.mymongo.find(...).skip(n)
db.mymongo.find(...).sort(...)
db.mymongo.findOne([query], [fields], [options], [readConcern])
db.mymongo.findOneAndDelete( filter, <optional params> ) - delete first matching document, optional parameters are: projection, sort, maxTimeMS
db.mymongo.findOneAndReplace( filter, replacement, <optional params> ) - replace first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument
db.mymongo.findOneAndUpdate( filter, update, <optional params> ) - update first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument
db.mymongo.getDB() get DB object associated with collection
db.mymongo.getPlanCache() get query plan cache associated with collection
db.mymongo.getIndexes()
db.mymongo.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )
db.mymongo.insert(obj)
db.mymongo.insertOne( obj, <optional params> ) - insert a document, optional parameters are: w, wtimeout, j
db.mymongo.insertMany( [objects], <optional params> ) - insert multiple documents, optional parameters are: w, wtimeout, j
db.mymongo.mapReduce( mapFunction , reduceFunction , <optional params> )
db.mymongo.aggregate( [pipeline], <optional params> ) - performs an aggregation on a collection; returns a cursor
db.mymongo.remove(query)
db.mymongo.replaceOne( filter, replacement, <optional params> ) - replace the first matching document, optional parameters are: upsert, w, wtimeout, j
db.mymongo.renameCollection( newName , <dropTarget> ) renames the collection.
db.mymongo.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection name
db.mymongo.save(obj)
db.mymongo.stats({scale: N, indexDetails: true/false, indexDetailsKey: <index key>, indexDetailsName: <index name>})
db.mymongo.storageSize() - includes free space allocated to this collection
db.mymongo.totalIndexSize() - size in bytes of all the indexes
db.mymongo.totalSize() - storage allocated for all data and indexes
db.mymongo.update( query, object[, upsert_bool, multi_bool] ) - instead of two flags, you can pass an object with fields: upsert, multi
db.mymongo.updateOne( filter, update, <optional params> ) - update the first matching document, optional parameters are: upsert, w, wtimeout, j
db.mymongo.updateMany( filter, update, <optional params> ) - update all matching documents, optional parameters are: upsert, w, wtimeout, j
db.mymongo.validate( <full> ) - SLOW
db.mymongo.getShardVersion() - only for use with sharding
db.mymongo.getShardDistribution() - prints statistics about data distribution in the cluster
db.mymongo.getSplitKeysForChunks( <maxChunkSize> ) - calculates split points over all chunks and returns splitter function
db.mymongo.getWriteConcern() - returns the write concern used for any operations on this collection, inherited from server/db if set
db.mymongo.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the collection
db.mymongo.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the collection
表级别帮助文档,使用db.表的名称.help()
例如:
> db.noPK.help()
DBCollection help
db.noPK.find().help() - show DBCursor help
db.noPK.bulkWrite( operations, <optional params> ) - bulk execute write operations, optional parameters are: w, wtimeout, j
db.noPK.count( query = {}, <optional params> ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS
db.noPK.copyTo(newColl) - duplicates collection by copying all documents to newColl; no indexes are copied.
db.noPK.convertToCapped(maxBytes) - calls {convertToCapped:‘noPK‘, size:maxBytes}} command
db.noPK.createIndex(keypattern[,options])
db.noPK.createIndexes([keypatterns], <options>)
db.noPK.dataSize()
db.noPK.deleteOne( filter, <optional params> ) - delete first matching document, optional parameters are: w, wtimeout, j
db.noPK.deleteMany( filter, <optional params> ) - delete all matching documents, optional parameters are: w, wtimeout, j
db.noPK.distinct( key, query, <optional params> ) - e.g. db.noPK.distinct( ‘x‘ ), optional parameters are: maxTimeMS
db.noPK.drop() drop the collection
db.noPK.dropIndex(index) - e.g. db.noPK.dropIndex( "indexName" ) or db.noPK.dropIndex( { "indexKey" : 1 } )
db.noPK.dropIndexes()
db.noPK.ensureIndex(keypattern[,options]) - DEPRECATED, use createIndex() instead
db.noPK.explain().help() - show explain help
db.noPK.reIndex()
db.noPK.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return.
e.g. db.noPK.find( {x:77} , {name:1, x:1} )
db.noPK.find(...).count()
db.noPK.find(...).limit(n)
db.noPK.find(...).skip(n)
db.noPK.find(...).sort(...)
db.noPK.findOne([query], [fields], [options], [readConcern])
db.noPK.findOneAndDelete( filter, <optional params> ) - delete first matching document, optional parameters are: projection, sort, maxTimeMS
db.noPK.findOneAndReplace( filter, replacement, <optional params> ) - replace first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument
db.noPK.findOneAndUpdate( filter, update, <optional params> ) - update first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument
db.noPK.getDB() get DB object associated with collection
db.noPK.getPlanCache() get query plan cache associated with collection
db.noPK.getIndexes()
db.noPK.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )
db.noPK.insert(obj)
db.noPK.insertOne( obj, <optional params> ) - insert a document, optional parameters are: w, wtimeout, j
db.noPK.insertMany( [objects], <optional params> ) - insert multiple documents, optional parameters are: w, wtimeout, j
db.noPK.mapReduce( mapFunction , reduceFunction , <optional params> )
db.noPK.aggregate( [pipeline], <optional params> ) - performs an aggregation on a collection; returns a cursor
db.noPK.remove(query)
db.noPK.replaceOne( filter, replacement, <optional params> ) - replace the first matching document, optional parameters are: upsert, w, wtimeout, j
db.noPK.renameCollection( newName , <dropTarget> ) renames the collection.
db.noPK.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection name
db.noPK.save(obj)
db.noPK.stats({scale: N, indexDetails: true/false, indexDetailsKey: <index key>, indexDetailsName: <index name>})
db.noPK.storageSize() - includes free space allocated to this collection
db.noPK.totalIndexSize() - size in bytes of all the indexes
db.noPK.totalSize() - storage allocated for all data and indexes
db.noPK.update( query, object[, upsert_bool, multi_bool] ) - instead of two flags, you can pass an object with fields: upsert, multi
db.noPK.updateOne( filter, update, <optional params> ) - update the first matching document, optional parameters are: upsert, w, wtimeout, j
db.noPK.updateMany( filter, update, <optional params> ) - update all matching documents, optional parameters are: upsert, w, wtimeout, j
db.noPK.validate( <full> ) - SLOW
db.noPK.getShardVersion() - only for use with sharding
db.noPK.getShardDistribution() - prints statistics about data distribution in the cluster
db.noPK.getSplitKeysForChunks( <maxChunkSize> ) - calculates split points over all chunks and returns splitter function
db.noPK.getWriteConcern() - returns the write concern used for any operations on this collection, inherited from server/db if set
db.noPK.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the collection
db.noPK.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the collection
>