跳转至

2. 命令

1. mongodb命令种类

db.     #数据有关(database,collection,document)
rs.     #复制集有关(replication set)
sh.     #分片集群有关(sharding cluster)

2. db.命令

#数据库对象级别、表级别、数据行级别相关操作
db.+[tab]*2
db.help()
db.t1.help()
[mongod@151 ~]$ mongo
MongoDB shell version: 3.2.22
connecting to: test
#1.按2下tab查看数据库级别所有操作
> db.
db.adminCommand(               db.eval(                       db.getRoles(                   db.listCommands(               db.serverBuildInfo(
db.auth(                       db.forceError(                 db.getSiblingDB(               db.loadServerScripts(          db.serverCmdLineOpts(
db.changeUserPassword(         db.fsyncLock(                  db.getSisterDB(                db.logout(                     db.serverStatus(
db.cloneCollection(            db.fsyncUnlock(                db.getSlaveOk(                 db.printCollectionStats(       db.setLogLevel(
db.cloneDatabase(              db.getCollection(              db.getUser(                    db.printReplicationInfo(       db.setProfilingLevel(
db.commandHelp(                db.getCollectionInfos(         db.getUsers(                   db.printShardingStatus(        db.setSlaveOk(
db.constructor                 db.getCollectionNames(         db.getWriteConcern(            db.printSlaveReplicationInfo(  db.setWriteConcern(
db.copyDatabase(               db.getLastError(               db.grantPrivilegesToRole(      db.propertyIsEnumerable(       db.shutdownServer(
db.createCollection(           db.getLastErrorCmd(            db.grantRolesToRole(           db.prototype                   db.stats(
db.createRole(                 db.getLastErrorObj(            db.grantRolesToUser(           db.removeUser(                 db.toLocaleString(
db.createUser(                 db.getLogComponents(           db.group(                      db.repairDatabase(             db.toString(
db.currentOP(                  db.getMongo(                   db.groupcmd(                   db.resetError(                 db.tojson(
db.currentOp(                  db.getName(                    db.groupeval(                  db.revokePrivilegesFromRole(   db.unsetWriteConcern(
db.dbEval(                     db.getPrevError(               db.hasOwnProperty(             db.revokeRolesFromRole(        db.updateRole(
db.dropAllRoles(               db.getProfilingLevel(          db.help(                       db.revokeRolesFromUser(        db.updateUser(
db.dropAllUsers(               db.getProfilingStatus(         db.hostInfo(                   db.runCommand(                 db.upgradeCheck(
db.dropDatabase(               db.getQueryOptions(            db.isMaster(                   db.runCommandWithMetadata(     db.upgradeCheckAllDBs(
db.dropRole(                   db.getReplicationInfo(         db.killOP(                     db.runReadCommand(             db.valueOf(
db.dropUser(                   db.getRole(                    db.killOp(                     db.serverBits(                 db.version(
> db.

#2.表级别所有操作命令
> db.t1.
db.t1.addIdIfNeeded(              db.t1.dropIndexes(                db.t1.getIndices(                 db.t1.initializeUnorderedBulkOp(  db.t1.setWriteConcern(
db.t1.aggregate(                  db.t1.ensureIndex(                db.t1.getMongo(                   db.t1.insert(                     db.t1.shellPrint(
db.t1.bulkWrite(                  db.t1.exists(                     db.t1.getName(                    db.t1.insertMany(                 db.t1.stats(
db.t1.constructor                 db.t1.explain(                    db.t1.getPagesInRAM(              db.t1.insertOne(                  db.t1.storageSize(
db.t1.convertToCapped(            db.t1.find(                       db.t1.getPlanCache(               db.t1.isCapped(                   db.t1.toLocaleString(
db.t1.convertToSingleObject(      db.t1.findAndModify(              db.t1.getQueryOptions(            db.t1.mapReduce(                  db.t1.toString(
db.t1.copyTo(                     db.t1.findOne(                    db.t1.getShardDistribution(       db.t1.pagesInRAM(                 db.t1.tojson(
db.t1.count(                      db.t1.findOneAndDelete(           db.t1.getShardVersion(            db.t1.propertyIsEnumerable(       db.t1.totalIndexSize(
db.t1.createIndex(                db.t1.findOneAndReplace(          db.t1.getSlaveOk(                 db.t1.prototype                   db.t1.totalSize(
db.t1.createIndexes(              db.t1.findOneAndUpdate(           db.t1.getSplitKeysForChunks(      db.t1.reIndex(                    db.t1.unsetWriteConcern(
db.t1.dataSize(                   db.t1.getCollection(              db.t1.getWriteConcern(            db.t1.remove(                     db.t1.update(
db.t1.deleteMany(                 db.t1.getDB(                      db.t1.group(                      db.t1.renameCollection(           db.t1.updateMany(
db.t1.deleteOne(                  db.t1.getDiskStorageStats(        db.t1.groupcmd(                   db.t1.replaceOne(                 db.t1.updateOne(
db.t1.diskStorageStats(           db.t1.getFullName(                db.t1.hasOwnProperty(             db.t1.runCommand(                 db.t1.validate(
db.t1.distinct(                   db.t1.getIndexKeys(               db.t1.hashAllDocs(                db.t1.runReadCommand(             db.t1.valueOf(
db.t1.drop(                       db.t1.getIndexSpecs(              db.t1.help(                       db.t1.save(                       db.t1.verify(
db.t1.dropIndex(                  db.t1.getIndexes(                 db.t1.initializeOrderedBulkOp(    db.t1.setSlaveOk(
> db.t1.


#3.行级别的操作(增删改查)
> db.t1.insert
db.t1.insert(      db.t1.insertMany(  db.t1.insertOne(
> db.t1.delete
db.t1.deleteMany(  db.t1.deleteOne(
> db.t1.update
db.t1.update(      db.t1.updateMany(  db.t1.updateOne(
> db.t1.find
db.t1.find(               db.t1.findOne(            db.t1.findOneAndReplace(
db.t1.findAndModify(      db.t1.findOneAndDelete(   db.t1.findOneAndUpdate(
#3.查看库级别帮助
> db.help
function () {
        print("DB methods:");
        print(
            "\tdb.adminCommand(nameOrDocument) - switches to 'admin' db, and runs command [ just calls db.runCommand(...) ]");
        print("\tdb.auth(username, password)");
        print("\tdb.cloneDatabase(fromhost)");
        print("\tdb.commandHelp(name) returns the help for the command");
        print("\tdb.copyDatabase(fromdb, todb, fromhost)");
        print("\tdb.createCollection(name, { size : ..., capped : ..., max : ... } )");
        print("\tdb.createUser(userDocument)");
        print("\tdb.currentOp() displays currently executing operations in the db");
        print("\tdb.dropDatabase()");
        print("\tdb.eval() - deprecated");
        print("\tdb.fsyncLock() flush data to disk and lock server for backups");
        print("\tdb.fsyncUnlock() unlocks server following a db.fsyncLock()");
        print("\tdb.getCollection(cname) same as db['cname'] or db.cname");
        print(
            "\tdb.getCollectionInfos([filter]) - returns a list that contains the names and options" +
            " of the db's collections");
        print("\tdb.getCollectionNames()");
        print("\tdb.getLastError() - just returns the err msg string");
        print("\tdb.getLastErrorObj() - return full status object");
        print("\tdb.getLogComponents()");
        print("\tdb.getMongo() get the server connection object");
        print("\tdb.getMongo().setSlaveOk() allow queries on a replication slave server");
        print("\tdb.getName()");
        print("\tdb.getPrevError()");
        print("\tdb.getProfilingLevel() - deprecated");
        print("\tdb.getProfilingStatus() - returns if profiling is on and slow threshold");
        print("\tdb.getReplicationInfo()");
        print("\tdb.getSiblingDB(name) get the db at the same server as this one");
        print(
            "\tdb.getWriteConcern() - returns the write concern used for any operations on this db, inherited from server object if set");
        print("\tdb.hostInfo() get details about the server's host");
        print("\tdb.isMaster() check replica primary status");
        print("\tdb.killOp(opid) kills the current operation in the db");
        print("\tdb.listCommands() lists all the db commands");
        print("\tdb.loadServerScripts() loads all the scripts in db.system.js");
        print("\tdb.logout()");
        print("\tdb.printCollectionStats()");
        print("\tdb.printReplicationInfo()");
        print("\tdb.printShardingStatus()");
        print("\tdb.printSlaveReplicationInfo()");
        print("\tdb.dropUser(username)");
        print("\tdb.repairDatabase()");
        print("\tdb.resetError()");
        print(
            "\tdb.runCommand(cmdObj) run a database command.  if cmdObj is a string, turns it into { cmdObj : 1 }");
        print("\tdb.serverStatus()");
        print("\tdb.setLogLevel(level,<component>)");
        print("\tdb.setProfilingLevel(level,<slowms>) 0=off 1=slow 2=all");
        print(
            "\tdb.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the db");
        print(
            "\tdb.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the db");
        print("\tdb.setVerboseShell(flag) display extra information in shell output");
        print("\tdb.shutdownServer()");
        print("\tdb.stats()");
        print("\tdb.version() current version of the server");

        return __magicNoPrint;
    }
>
>
> db.help()
DB methods:
        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 command
        db.copyDatabase(fromdb, todb, fromhost)
        db.createCollection(name, { size : ..., capped : ..., max : ... } )
        db.createUser(userDocument)
        db.currentOp() displays currently executing operations in the db
        db.dropDatabase()
        db.eval() - deprecated
        db.fsyncLock() flush data to disk and lock server for backups
        db.fsyncUnlock() unlocks server following a db.fsyncLock()
        db.getCollection(cname) same as db['cname'] or db.cname
        db.getCollectionInfos([filter]) - returns a list that contains the names and options of the db's collections
        db.getCollectionNames()
        db.getLastError() - just returns the err msg string
        db.getLastErrorObj() - return full status object
        db.getLogComponents()
        db.getMongo() get the server connection object
        db.getMongo().setSlaveOk() allow queries on a replication slave server
        db.getName()
        db.getPrevError()
        db.getProfilingLevel() - deprecated
        db.getProfilingStatus() - returns if profiling is on and slow threshold
        db.getReplicationInfo()
        db.getSiblingDB(name) get the db at the same server as this one
        db.getWriteConcern() - returns the write concern used for any operations on this db, inherited from server object if set
        db.hostInfo() get details about the server's host
        db.isMaster() check replica primary status
        db.killOp(opid) kills the current operation in the db
        db.listCommands() lists all the db commands
        db.loadServerScripts() loads all the scripts in db.system.js
        db.logout()
        db.printCollectionStats()
        db.printReplicationInfo()
        db.printShardingStatus()
        db.printSlaveReplicationInfo()
        db.dropUser(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.setLogLevel(level,<component>)
        db.setProfilingLevel(level,<slowms>) 0=off 1=slow 2=all
        db.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the db
        db.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the db
        db.setVerboseShell(flag) display extra information in shell output
        db.shutdownServer()
        db.stats()
        db.version() current version of the server
>

#2.表级别的帮助
> db.t1.help()
DBCollection help
        db.t1.find().help() - show DBCursor help
        db.t1.bulkWrite( operations, <optional params> ) - bulk execute write operations, optional parameters are: w, wtimeout, j
        db.t1.count( query = {}, <optional params> ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS
        db.t1.copyTo(newColl) - duplicates collection by copying all documents to newColl; no indexes are copied.
        db.t1.convertToCapped(maxBytes) - calls {convertToCapped:'t1', size:maxBytes}} command
        db.t1.createIndex(keypattern[,options])
        db.t1.createIndexes([keypatterns], <options>)
        db.t1.dataSize()
        db.t1.deleteOne( filter, <optional params> ) - delete first matching document, optional parameters are: w, wtimeout, j
        db.t1.deleteMany( filter, <optional params> ) - delete all matching documents, optional parameters are: w, wtimeout, j
        db.t1.distinct( key, query, <optional params> ) - e.g. db.t1.distinct( 'x' ), optional parameters are: maxTimeMS
        db.t1.drop() drop the collection
        db.t1.dropIndex(index) - e.g. db.t1.dropIndex( "indexName" ) or db.t1.dropIndex( { "indexKey" : 1 } )
        db.t1.dropIndexes()
        db.t1.ensureIndex(keypattern[,options]) - DEPRECATED, use createIndex() instead
        db.t1.explain().help() - show explain help
        db.t1.reIndex()
        db.t1.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return.
                                                      e.g. db.t1.find( {x:77} , {name:1, x:1} )
        db.t1.find(...).count()
        db.t1.find(...).limit(n)
        db.t1.find(...).skip(n)
        db.t1.find(...).sort(...)
        db.t1.findOne([query], [fields], [options], [readConcern])
        db.t1.findOneAndDelete( filter, <optional params> ) - delete first matching document, optional parameters are: projection, sort, maxTimeMS
        db.t1.findOneAndReplace( filter, replacement, <optional params> ) - replace first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument
        db.t1.findOneAndUpdate( filter, update, <optional params> ) - update first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument
        db.t1.getDB() get DB object associated with collection
        db.t1.getPlanCache() get query plan cache associated with collection
        db.t1.getIndexes()
        db.t1.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )
        db.t1.insert(obj)
        db.t1.insertOne( obj, <optional params> ) - insert a document, optional parameters are: w, wtimeout, j
        db.t1.insertMany( [objects], <optional params> ) - insert multiple documents, optional parameters are: w, wtimeout, j
        db.t1.mapReduce( mapFunction , reduceFunction , <optional params> )
        db.t1.aggregate( [pipeline], <optional params> ) - performs an aggregation on a collection; returns a cursor
        db.t1.remove(query)
        db.t1.replaceOne( filter, replacement, <optional params> ) - replace the first matching document, optional parameters are: upsert, w, wtimeout, j
        db.t1.renameCollection( newName , <dropTarget> ) renames the collection.
        db.t1.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection name
        db.t1.save(obj)
        db.t1.stats({scale: N, indexDetails: true/false, indexDetailsKey: <index key>, indexDetailsName: <index name>})
        db.t1.storageSize() - includes free space allocated to this collection
        db.t1.totalIndexSize() - size in bytes of all the indexes
        db.t1.totalSize() - storage allocated for all data and indexes
        db.t1.update( query, object[, upsert_bool, multi_bool] ) - instead of two flags, you can pass an object with fields: upsert, multi
        db.t1.updateOne( filter, update, <optional params> ) - update the first matching document, optional parameters are: upsert, w, wtimeout, j
        db.t1.updateMany( filter, update, <optional params> ) - update all matching documents, optional parameters are: upsert, w, wtimeout, j
        db.t1.validate( <full> ) - SLOW
        db.t1.getShardVersion() - only for use with sharding
        db.t1.getShardDistribution() - prints statistics about data distribution in the cluster
        db.t1.getSplitKeysForChunks( <maxChunkSize> ) - calculates split points over all chunks and returns splitter function
        db.t1.getWriteConcern() - returns the write concern used for any operations on this collection, inherited from server/db if set
        db.t1.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the collection
        db.t1.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the collection
>

3. rs. 命令(后面用到)

#1.命令
> rs.
rs.add(                        rs.printReplicationInfo(
rs.addArb(                     rs.printSlaveReplicationInfo(
rs.apply(                      rs.propertyIsEnumerable(
rs.bind(                       rs.prototype
rs.call(                       rs.reconfig(
rs.conf(                       rs.remove(
rs.config(                     rs.slaveOk(
rs.constructor                 rs.status(
rs.debug                       rs.stepDown(
rs.freeze(                     rs.syncFrom(
rs.hasOwnProperty(             rs.toLocaleString(
rs.help(                       rs.toString(
rs.initiate(                   rs.valueOf(
rs.isMaster(

#2.帮助
> rs.help()
        rs.status()                                { replSetGetStatus : 1 } checks repl set status
        rs.initiate()                              { replSetInitiate : null } initiates set with default settings
        rs.initiate(cfg)                           { replSetInitiate : cfg } initiates set with configuration cfg
        rs.conf()                                  get the current configuration object from local.system.replset
        rs.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([stepdownSecs, catchUpSecs])   step down as primary (disconnects)
        rs.syncFrom(hostportstr)                   make a secondary sync from the given member
        rs.freeze(secs)                            make a node ineligible to become primary for the time specified
        rs.remove(hostportstr)                     remove a host from the replica set (disconnects)
        rs.slaveOk()                               allow queries on secondary nodes

        rs.printReplicationInfo()                  check oplog size and time range
        rs.printSlaveReplicationInfo()             check replica set members and replication lag
        db.isMaster()                              check who is primary

        reconfiguration helpers disconnect from the database so the shell will display
        an error, even if the command succeeds.

4. sh. 命令(后面用到)

#1.命令
> sh.
sh.addShard(                sh.moveChunk(
sh.addShardTag(             sh.propertyIsEnumerable(
sh.addTagRange(             sh.prototype
sh.apply(                   sh.removeShardTag(
sh.bind(                    sh.removeTagRange(
sh.call(                    sh.setBalancerState(
sh.constructor              sh.shardCollection(
sh.disableBalancing(        sh.splitAt(
sh.enableBalancing(         sh.splitFind(
sh.enableSharding(          sh.startBalancer(
sh.getActiveMigrations(     sh.status(
sh.getBalancerHost(         sh.stopBalancer(
sh.getBalancerLockDetails(  sh.toLocaleString(
sh.getBalancerState(        sh.toString(
sh.getBalancerWindow(       sh.valueOf(
sh.getRecentFailedRounds(   sh.waitForBalancer(
sh.getRecentMigrations(     sh.waitForBalancerOff(
sh.hasOwnProperty(          sh.waitForDLock(
sh.help(                    sh.waitForPingChange(
sh.isBalancerRunning(

#2.帮助信息
> sh.help()
        sh.addShard( host )                       server:port OR setname/server:port
        sh.enableSharding(dbname)                 enables sharding on the database dbname
        sh.shardCollection(fullName,key,unique)   shards the collection
        sh.splitFind(fullName,find)               splits the chunk that find is in at the median
        sh.splitAt(fullName,middle)               splits the chunk that middle is in at middle
        sh.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=off
        sh.getBalancerState()                     return true if enabled
        sh.isBalancerRunning()                    return true if the balancer has work in progress on any mongos
        sh.disableBalancing(coll)                 disable balancing on one collection
        sh.enableBalancing(coll)                  re-enable balancing on one collection
        sh.addShardTag(shard,tag)                 adds the tag to the shard
        sh.removeShardTag(shard,tag)              removes the tag from the shard
        sh.addTagRange(fullName,min,max,tag)      tags the specified range of the given collection
        sh.removeTagRange(fullName,min,max,tag)   removes the tagged range of the given collection
        sh.status()                               prints a general overview of the cluster

5. 常用命令

#1.查看当前db版本
db.version()

#2.显示当前库
db
db.getName()

#3.查看所有库
show dbs
show databases

#4.切换数据库
use local

#5.查看所有表
show tables;
show collections;

#6.显示当前库状态
db.stats()

#7.查看当前库的连接机器的地址
db.getMongo()
#1.查看当前db版本
> db.version()
3.2.22

#2.显示当前库
> db
test
> db.getName()
test

#3.查看所有库
> show dbs
local  0.000GB
> show databases
local  0.000GB


#4.切换数据库
> use local
switched to db local

#5.查看所有表
> show tables;
startup_log
> show collections;
startup_log

#6.显示当前库状态
> db.stats()
{
        "db" : "local",
        "collections" : 1,
        "objects" : 2,
        "avgObjSize" : 1523,
        "dataSize" : 3046,
        "storageSize" : 32768,
        "numExtents" : 0,
        "indexes" : 1,
        "indexSize" : 32768,
        "ok" : 1
}

#7.查看当前库的连接机器的地址
> db.getMongo()
connection to 127.0.0.1
#补充:
1.mongodb默认存在的库
    test库:是登录时默认的库,是虚拟库
2.管理mongodb有关的系统库
    admin库:系统预留库,mongodb系统管理库
    local库:本地预留库,存储关键日志信息

6. mongodb对象操作命令

6.1 创建数据库

#当use的时候,系统会自动创建一个数据库
#如果use之后没有创建任何集合,则系统就会删除这个库
use chupeng
#1.不创建集合,则库不存在
> use chupeng
switched to db chupeng
> show dbs
local  0.000GB

#2.创建集合,则库自动有了
> db.t1.insert({id:101})
WriteResult({ "nInserted" : 1 })
> show dbs
chupeng  0.000GB
local    0.000GB

6.2 删除库

use test
db.dropDatabase()
#如果没有use任何库,则默认会删除test库
> show dbs
chupeng  0.000GB
local    0.000GB
> use chupeng
switched to db chupeng
> db.dropDatabase()
{ "dropped" : "chupeng", "ok" : 1 }
> show dbs
local  0.000GB

6.3 创建集合方法1

use app
db.createCollection('a')
db.createCollection('b')
show collections
db.getCollectionNames()
> use app
switched to db app
> db.createCollection('a')
{ "ok" : 1 }
> db.createCollection('b')
{ "ok" : 1 }
> show collections
a
b
> db.getCollectionNames()
[ "a", "b" ]

6.4 创建集合方法2

#1.创建库
use oldboy

#2.创建表
db.stu.insert({name:"zhangsan"})
db.stu.insert({id:101,name:"zhangsan",age:20,gender:"m"})

#3.查看表
show tables;

#4.查看表中数据
db.stu.find({})

#5.以json格式显示数据
db.stu.find({}).pretty()
> use oldboy
switched to db oldboy
> db.stu.insert({name:"zhangsan"})
WriteResult({ "nInserted" : 1 })
> db.stu.insert({id:101,name:"zhangsan",age:20,gender:"20"})
WriteResult({ "nInserted" : 1 })
> show tables;
stu
> db.stu.find({})
{ "_id" : ObjectId("609b53dd00177802e2f209b4"), "name" : "zhangsan" }
{ "_id" : ObjectId("609b541900177802e2f209b5"), "id" : 101, "name" : "zhangsan", "age" : 20, "gender" : "20" }
> db.stu.find({}).pretty()
{ "_id" : ObjectId("609b53dd00177802e2f209b4"), "name" : "zhangsan" }
{
        "_id" : ObjectId("609b541900177802e2f209b5"),
        "id" : 101,
        "name" : "zhangsan",
        "age" : 20,
        "gender" : "20"
}

6.5 删除表

use oldboy
#1.集合改名
db.stu.renameCollection("stu1")
#2.删除集合
db.stu1.drop()
> use oldboy
switched to db oldboy
> db.stu.renameCollection("stu1")
{ "ok" : 1 }
> show tables
stu1
> db.stu1.drop()
true
> show tables
>

6.6 使用for循环批量插入数据

use app
for(i=0;i<10000;i++){db.log.insert({"uid":i,"name":"mongodb","age":6,"date":new Date()})}
> use app
switched to db app
> for(i=0;i<10000;i++){db.log.insert({"uid":i,"name":"mongodb","age":6,"date":new Date()})}
WriteResult({ "nInserted" : 1 })
> show tables
a
b
log
>
> db.log.find()
{ "_id" : ObjectId("609b554400177802e2f209b6"), "uid" : 0, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.840Z") }
{ "_id" : ObjectId("609b554400177802e2f209b7"), "uid" : 1, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.845Z") }
{ "_id" : ObjectId("609b554400177802e2f209b8"), "uid" : 2, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.845Z") }
{ "_id" : ObjectId("609b554400177802e2f209b9"), "uid" : 3, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.846Z") }
{ "_id" : ObjectId("609b554400177802e2f209ba"), "uid" : 4, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.846Z") }
{ "_id" : ObjectId("609b554400177802e2f209bb"), "uid" : 5, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.847Z") }
{ "_id" : ObjectId("609b554400177802e2f209bc"), "uid" : 6, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.847Z") }
{ "_id" : ObjectId("609b554400177802e2f209bd"), "uid" : 7, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.847Z") }
{ "_id" : ObjectId("609b554400177802e2f209be"), "uid" : 8, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.848Z") }
{ "_id" : ObjectId("609b554400177802e2f209bf"), "uid" : 9, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.849Z") }
{ "_id" : ObjectId("609b554400177802e2f209c0"), "uid" : 10, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.849Z") }
{ "_id" : ObjectId("609b554400177802e2f209c1"), "uid" : 11, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.849Z") }
{ "_id" : ObjectId("609b554400177802e2f209c2"), "uid" : 12, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.849Z") }
{ "_id" : ObjectId("609b554400177802e2f209c3"), "uid" : 13, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.850Z") }
{ "_id" : ObjectId("609b554400177802e2f209c4"), "uid" : 14, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.850Z") }
{ "_id" : ObjectId("609b554400177802e2f209c5"), "uid" : 15, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.850Z") }
{ "_id" : ObjectId("609b554400177802e2f209c6"), "uid" : 16, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.851Z") }
{ "_id" : ObjectId("609b554400177802e2f209c7"), "uid" : 17, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.851Z") }
{ "_id" : ObjectId("609b554400177802e2f209c8"), "uid" : 18, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.851Z") }
{ "_id" : ObjectId("609b554400177802e2f209c9"), "uid" : 19, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.852Z") }
Type "it" for more
>

6.7 查询记录

use app
#1.查看所有记录
db.log.find()

#默认每页显示20条,可以使用it查看下一页数据
#2.修改每页显示记录数
DBQuery.shellBatchSize=50;
db.log.find()

#3.查看第一条记录
db.log.findOne()

#4.查看记录数
db.log.count()

#5.条件查询
use oldboy
db.stu.find({"name":"zhangsan"})
#查看前20条记录
> db.log.find()
{ "_id" : ObjectId("609b554400177802e2f209b6"), "uid" : 0, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.840Z") }
{ "_id" : ObjectId("609b554400177802e2f209b7"), "uid" : 1, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.845Z") }
{ "_id" : ObjectId("609b554400177802e2f209b8"), "uid" : 2, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.845Z") }
{ "_id" : ObjectId("609b554400177802e2f209b9"), "uid" : 3, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.846Z") }
{ "_id" : ObjectId("609b554400177802e2f209ba"), "uid" : 4, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.846Z") }
{ "_id" : ObjectId("609b554400177802e2f209bb"), "uid" : 5, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.847Z") }
{ "_id" : ObjectId("609b554400177802e2f209bc"), "uid" : 6, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.847Z") }
{ "_id" : ObjectId("609b554400177802e2f209bd"), "uid" : 7, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.847Z") }
{ "_id" : ObjectId("609b554400177802e2f209be"), "uid" : 8, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.848Z") }
{ "_id" : ObjectId("609b554400177802e2f209bf"), "uid" : 9, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.849Z") }
{ "_id" : ObjectId("609b554400177802e2f209c0"), "uid" : 10, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.849Z") }
{ "_id" : ObjectId("609b554400177802e2f209c1"), "uid" : 11, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.849Z") }
{ "_id" : ObjectId("609b554400177802e2f209c2"), "uid" : 12, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.849Z") }
{ "_id" : ObjectId("609b554400177802e2f209c3"), "uid" : 13, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.850Z") }
{ "_id" : ObjectId("609b554400177802e2f209c4"), "uid" : 14, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.850Z") }
{ "_id" : ObjectId("609b554400177802e2f209c5"), "uid" : 15, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.850Z") }
{ "_id" : ObjectId("609b554400177802e2f209c6"), "uid" : 16, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.851Z") }
{ "_id" : ObjectId("609b554400177802e2f209c7"), "uid" : 17, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.851Z") }
{ "_id" : ObjectId("609b554400177802e2f209c8"), "uid" : 18, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.851Z") }
{ "_id" : ObjectId("609b554400177802e2f209c9"), "uid" : 19, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.852Z") }
Type "it" for more
#翻页查看另外20条
> it
{ "_id" : ObjectId("609b554400177802e2f209ca"), "uid" : 20, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.852Z") }
{ "_id" : ObjectId("609b554400177802e2f209cb"), "uid" : 21, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.852Z") }
{ "_id" : ObjectId("609b554400177802e2f209cc"), "uid" : 22, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.852Z") }
{ "_id" : ObjectId("609b554400177802e2f209cd"), "uid" : 23, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.853Z") }
{ "_id" : ObjectId("609b554400177802e2f209ce"), "uid" : 24, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.853Z") }
{ "_id" : ObjectId("609b554400177802e2f209cf"), "uid" : 25, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.853Z") }
{ "_id" : ObjectId("609b554400177802e2f209d0"), "uid" : 26, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.854Z") }
{ "_id" : ObjectId("609b554400177802e2f209d1"), "uid" : 27, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.854Z") }
{ "_id" : ObjectId("609b554400177802e2f209d2"), "uid" : 28, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.854Z") }
{ "_id" : ObjectId("609b554400177802e2f209d3"), "uid" : 29, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.854Z") }
{ "_id" : ObjectId("609b554400177802e2f209d4"), "uid" : 30, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.855Z") }
{ "_id" : ObjectId("609b554400177802e2f209d5"), "uid" : 31, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.855Z") }
{ "_id" : ObjectId("609b554400177802e2f209d6"), "uid" : 32, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.855Z") }
{ "_id" : ObjectId("609b554400177802e2f209d7"), "uid" : 33, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.856Z") }
{ "_id" : ObjectId("609b554400177802e2f209d8"), "uid" : 34, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.856Z") }
{ "_id" : ObjectId("609b554400177802e2f209d9"), "uid" : 35, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.856Z") }
{ "_id" : ObjectId("609b554400177802e2f209da"), "uid" : 36, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.856Z") }
{ "_id" : ObjectId("609b554400177802e2f209db"), "uid" : 37, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.857Z") }
{ "_id" : ObjectId("609b554400177802e2f209dc"), "uid" : 38, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.857Z") }
{ "_id" : ObjectId("609b554400177802e2f209dd"), "uid" : 39, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.857Z") }
Type "it" for more
>


#设置每页显示的记录条数为50
> DBQuery.shellBatchSize=50;
50
> db.log.find()
{ "_id" : ObjectId("609b554400177802e2f209b6"), "uid" : 0, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.840Z") }
{ "_id" : ObjectId("609b554400177802e2f209b7"), "uid" : 1, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.845Z") }
{ "_id" : ObjectId("609b554400177802e2f209b8"), "uid" : 2, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.845Z") }
{ "_id" : ObjectId("609b554400177802e2f209b9"), "uid" : 3, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.846Z") }
{ "_id" : ObjectId("609b554400177802e2f209ba"), "uid" : 4, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.846Z") }
{ "_id" : ObjectId("609b554400177802e2f209bb"), "uid" : 5, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.847Z") }
{ "_id" : ObjectId("609b554400177802e2f209bc"), "uid" : 6, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.847Z") }
{ "_id" : ObjectId("609b554400177802e2f209bd"), "uid" : 7, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.847Z") }
{ "_id" : ObjectId("609b554400177802e2f209be"), "uid" : 8, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.848Z") }
{ "_id" : ObjectId("609b554400177802e2f209bf"), "uid" : 9, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.849Z") }
{ "_id" : ObjectId("609b554400177802e2f209c0"), "uid" : 10, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.849Z") }
{ "_id" : ObjectId("609b554400177802e2f209c1"), "uid" : 11, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.849Z") }
{ "_id" : ObjectId("609b554400177802e2f209c2"), "uid" : 12, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.849Z") }
{ "_id" : ObjectId("609b554400177802e2f209c3"), "uid" : 13, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.850Z") }
{ "_id" : ObjectId("609b554400177802e2f209c4"), "uid" : 14, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.850Z") }
{ "_id" : ObjectId("609b554400177802e2f209c5"), "uid" : 15, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.850Z") }
{ "_id" : ObjectId("609b554400177802e2f209c6"), "uid" : 16, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.851Z") }
{ "_id" : ObjectId("609b554400177802e2f209c7"), "uid" : 17, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.851Z") }
{ "_id" : ObjectId("609b554400177802e2f209c8"), "uid" : 18, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.851Z") }
{ "_id" : ObjectId("609b554400177802e2f209c9"), "uid" : 19, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.852Z") }
{ "_id" : ObjectId("609b554400177802e2f209ca"), "uid" : 20, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.852Z") }
{ "_id" : ObjectId("609b554400177802e2f209cb"), "uid" : 21, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.852Z") }
{ "_id" : ObjectId("609b554400177802e2f209cc"), "uid" : 22, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.852Z") }
{ "_id" : ObjectId("609b554400177802e2f209cd"), "uid" : 23, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.853Z") }
{ "_id" : ObjectId("609b554400177802e2f209ce"), "uid" : 24, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.853Z") }
{ "_id" : ObjectId("609b554400177802e2f209cf"), "uid" : 25, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.853Z") }
{ "_id" : ObjectId("609b554400177802e2f209d0"), "uid" : 26, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.854Z") }
{ "_id" : ObjectId("609b554400177802e2f209d1"), "uid" : 27, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.854Z") }
{ "_id" : ObjectId("609b554400177802e2f209d2"), "uid" : 28, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.854Z") }
{ "_id" : ObjectId("609b554400177802e2f209d3"), "uid" : 29, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.854Z") }
{ "_id" : ObjectId("609b554400177802e2f209d4"), "uid" : 30, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.855Z") }
{ "_id" : ObjectId("609b554400177802e2f209d5"), "uid" : 31, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.855Z") }
{ "_id" : ObjectId("609b554400177802e2f209d6"), "uid" : 32, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.855Z") }
{ "_id" : ObjectId("609b554400177802e2f209d7"), "uid" : 33, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.856Z") }
{ "_id" : ObjectId("609b554400177802e2f209d8"), "uid" : 34, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.856Z") }
{ "_id" : ObjectId("609b554400177802e2f209d9"), "uid" : 35, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.856Z") }
{ "_id" : ObjectId("609b554400177802e2f209da"), "uid" : 36, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.856Z") }
{ "_id" : ObjectId("609b554400177802e2f209db"), "uid" : 37, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.857Z") }
{ "_id" : ObjectId("609b554400177802e2f209dc"), "uid" : 38, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.857Z") }
{ "_id" : ObjectId("609b554400177802e2f209dd"), "uid" : 39, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.857Z") }
{ "_id" : ObjectId("609b554400177802e2f209de"), "uid" : 40, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.858Z") }
{ "_id" : ObjectId("609b554400177802e2f209df"), "uid" : 41, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.858Z") }
{ "_id" : ObjectId("609b554400177802e2f209e0"), "uid" : 42, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.858Z") }
{ "_id" : ObjectId("609b554400177802e2f209e1"), "uid" : 43, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.858Z") }
{ "_id" : ObjectId("609b554400177802e2f209e2"), "uid" : 44, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.859Z") }
{ "_id" : ObjectId("609b554400177802e2f209e3"), "uid" : 45, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.859Z") }
{ "_id" : ObjectId("609b554400177802e2f209e4"), "uid" : 46, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.859Z") }
{ "_id" : ObjectId("609b554400177802e2f209e5"), "uid" : 47, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.859Z") }
{ "_id" : ObjectId("609b554400177802e2f209e6"), "uid" : 48, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.860Z") }
{ "_id" : ObjectId("609b554400177802e2f209e7"), "uid" : 49, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.860Z") }
Type "it" for more
>

#查看第一条记录
> db.log.findOne()
{
        "_id" : ObjectId("609b554400177802e2f209b6"),
        "uid" : 0,
        "name" : "mongodb",
        "age" : 6,
        "date" : ISODate("2021-05-12T04:10:44.840Z")
}

#查看记录数
> db.log.count()
10000

#条件查询
> db.log.find({uid:10})
{ "_id" : ObjectId("609b554400177802e2f209c0"), "uid" : 10, "name" : "mongodb", "age" : 6, "date" : ISODate("2021-05-12T04:10:44.849Z") }

#不能使用=
> db.log.find({uid=10})
2021-05-12T12:15:46.318+0800 E QUERY    [thread1] SyntaxError: missing : after property id @(shell):1:16

6.8 查看集合存储信息

db.log.stats()          #集合的状态
db.log.dataSize()       #集合中数据的原始大小(不常用)
db.log.totalIndexSize()  #集合中索引数据的原始大小(不常用)
db.log.totalSize()      #集合中索引+数据压缩存储之后的大小(常用)
db.log.storageSize()    #集合中数据压缩存储的大小
#1.集合状态
> db.log.stats()
{
        "ns" : "app.log",
        "count" : 10000,
        "size" : 800000,
        "avgObjSize" : 80,
        "storageSize" : 258048,
        "capped" : false,
        "wiredTiger" : {
                "metadata" : {
                        "formatVersion" : 1
                },
                "creationString" : "access_pattern_hint=none,allocation_size=4KB,app_metadata=(formatVersion=1),block_allocation=best,block_compressor=snappy,cache_resident=false,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=false,extractor=,format=btree,huffman_key=,huffman_value=,ignore_in_memory_cache_size=false,immutable=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=q,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=64MB,log=(enabled=true),lsm=(auto_throttle=true,bloom=true,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=false,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_max=15,merge_min=0),memory_page_max=10m,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,type=file,value_format=u",
                "type" : "file",
                "uri" : "statistics:table:collection-8-4755642625882419929",
                "LSM" : {
                        "bloom filter false positives" : 0,
                        "bloom filter hits" : 0,
                        "bloom filter misses" : 0,
                        "bloom filter pages evicted from cache" : 0,
                        "bloom filter pages read into cache" : 0,
                        "bloom filters in the LSM tree" : 0,
                        "chunks in the LSM tree" : 0,
                        "highest merge generation in the LSM tree" : 0,
                        "queries that could have benefited from a Bloom filter that did not exist" : 0,
                        "sleep for LSM checkpoint throttle" : 0,
                        "sleep for LSM merge throttle" : 0,
                        "total size of bloom filters" : 0
                },
                "block-manager" : {
                        "allocations requiring file extension" : 32,
                        "blocks allocated" : 32,
                        "blocks freed" : 0,
                        "checkpoint size" : 245760,
                        "file allocation unit size" : 4096,
                        "file bytes available for reuse" : 0,
                        "file magic number" : 120897,
                        "file major version number" : 1,
                        "file size in bytes" : 258048,
                        "minor version number" : 0
                },
                "btree" : {
                        "btree checkpoint generation" : 14,
                        "column-store fixed-size leaf pages" : 0,
                        "column-store internal pages" : 0,
                        "column-store variable-size RLE encoded values" : 0,
                        "column-store variable-size deleted values" : 0,
                        "column-store variable-size leaf pages" : 0,
                        "fixed-record size" : 0,
                        "maximum internal page key size" : 368,
                        "maximum internal page size" : 4096,
                        "maximum leaf page key size" : 2867,
                        "maximum leaf page size" : 32768,
                        "maximum leaf page value size" : 67108864,
                        "maximum tree depth" : 3,
                        "number of key/value pairs" : 0,
                        "overflow pages" : 0,
                        "pages rewritten by compaction" : 0,
                        "row-store internal pages" : 0,
                        "row-store leaf pages" : 0
                },
                "cache" : {
                        "bytes currently in the cache" : 1695033,
                        "bytes read into cache" : 0,
                        "bytes written from cache" : 853029,
                        "checkpoint blocked page eviction" : 0,
                        "data source pages selected for eviction unable to be evicted" : 0,
                        "hazard pointer blocked page eviction" : 0,
                        "in-memory page passed criteria to be split" : 0,
                        "in-memory page splits" : 0,
                        "internal pages evicted" : 0,
                        "internal pages split during eviction" : 0,
                        "leaf pages split during eviction" : 0,
                        "modified pages evicted" : 0,
                        "overflow pages read into cache" : 0,
                        "overflow values cached in memory" : 0,
                        "page split during eviction deepened the tree" : 0,
                        "page written requiring lookaside records" : 0,
                        "pages read into cache" : 0,
                        "pages read into cache requiring lookaside entries" : 0,
                        "pages requested from the cache" : 10086,
                        "pages written from cache" : 31,
                        "pages written requiring in-memory restoration" : 0,
                        "tracked dirty bytes in the cache" : 0,
                        "unmodified pages evicted" : 0
                },
                "cache_walk" : {
                        "Average difference between current eviction generation when the page was last considered" : 0,
                        "Average on-disk page image size seen" : 0,
                        "Clean pages currently in cache" : 0,
                        "Current eviction generation" : 0,
                        "Dirty pages currently in cache" : 0,
                        "Entries in the root page" : 0,
                        "Internal pages currently in cache" : 0,
                        "Leaf pages currently in cache" : 0,
                        "Maximum difference between current eviction generation when the page was last considered" : 0,
                        "Maximum page size seen" : 0,
                        "Minimum on-disk page image size seen" : 0,
                        "On-disk page image sizes smaller than a single allocation unit" : 0,
                        "Pages created in memory and never written" : 0,
                        "Pages currently queued for eviction" : 0,
                        "Pages that could not be queued for eviction" : 0,
                        "Refs skipped during cache traversal" : 0,
                        "Size of the root page" : 0,
                        "Total number of pages currently in cache" : 0
                },
                "compression" : {
                        "compressed pages read" : 0,
                        "compressed pages written" : 30,
                        "page written failed to compress" : 0,
                        "page written was too small to compress" : 1,
                        "raw compression call failed, additional data available" : 0,
                        "raw compression call failed, no additional data available" : 0,
                        "raw compression call succeeded" : 0
                },
                "cursor" : {
                        "bulk-loaded cursor-insert calls" : 0,
                        "create calls" : 2,
                        "cursor-insert key and value bytes inserted" : 821426,
                        "cursor-remove key bytes removed" : 0,
                        "cursor-update value bytes updated" : 0,
                        "insert calls" : 10000,
                        "next calls" : 10608,
                        "prev calls" : 1,
                        "remove calls" : 0,
                        "reset calls" : 10093,
                        "restarted searches" : 0,
                        "search calls" : 0,
                        "search near calls" : 78,
                        "truncate calls" : 0,
                        "update calls" : 0
                },
                "reconciliation" : {
                        "dictionary matches" : 0,
                        "fast-path pages deleted" : 0,
                        "internal page key bytes discarded using suffix compression" : 59,
                        "internal page multi-block writes" : 0,
                        "internal-page overflow keys" : 0,
                        "leaf page key bytes discarded using prefix compression" : 0,
                        "leaf page multi-block writes" : 1,
                        "leaf-page overflow keys" : 0,
                        "maximum blocks required for a page" : 30,
                        "overflow values written" : 0,
                        "page checksum matches" : 0,
                        "page reconciliation calls" : 2,
                        "page reconciliation calls for eviction" : 0,
                        "pages deleted" : 0
                },
                "session" : {
                        "object compaction" : 0,
                        "open cursor count" : 2
                },
                "transaction" : {
                        "update conflicts" : 0
                }
        },
        "nindexes" : 1,
        "totalIndexSize" : 98304,
        "indexSizes" : {
                "_id_" : 98304
        },
        "ok" : 1
}
#2.集合中数据的原始大小(不常用)
> db.log.dataSize()
800000


#3.集合中索引数据的原始大小(不常用)
> db.log.totalIndexSize()
98304


#4.集合中索引+数据压缩存储之后的大小(常用)
> db.log.totalSize()
356352


#5.集合中数据压缩存储的大小
> db.log.storageSize()
258048

最后更新: 2022-02-20 11:21:58