当前位置:Gxlcms > 数据库问题 > MongoDB的安装,mongod和mongo的区别

MongoDB的安装,mongod和mongo的区别

时间:2021-07-01 10:21:17 帮助过:15人阅读

> db.stats()
{
        "db" : "test",
        "collections" : 0,
        "views" : 0,
        "objects" : 0,
        "avgObjSize" : 0,
        "dataSize" : 0,
        "storageSize" : 0,
        "numExtents" : 0,
        "indexes" : 0,
        "indexSize" : 0,
        "fileSize" : 0,
        "fsUsedSize" : 0,
        "fsTotalSize" : 0,
        "ok" : 1
}
技术图片

 

db.help()将列出一个命令列表

技术图片
> db.help()
DB methods:
        db.adminCommand(nameOrDocument) - switches to ‘admin‘ db, and runs command [just calls db.runCommand(...)]
        db.aggregate([pipeline], {options}) - performs a collectionless aggregation on this database; returns a cursor
        db.auth(username, password)
        db.cloneDatabase(fromhost) - deprecated
        db.commandHelp(name) returns the help for the command
        db.copyDatabase(fromdb, todb, fromhost) - deprecated
        db.createCollection(name, {size: ..., capped: ..., max: ...})
        db.createView(name, viewOn, [{$operator: {...}}, ...], {viewOptions})
        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
>
技术图片

 

 

四 最后

  1. 注意 mongod 和 mongo 的区别

  前者是启用MongoDB进程,后者是对MongoDB进行连接操作

  2. 执行 mongod 需要 配置路径 进行启用,单纯的双击 mongod.exe文件会闪出,正确的是执行mongod --dbpath 命令

  3. 在执行mongod命令启用MongoDB进程(服务器)的基础上,再使用mongo 对其进行连接操作,

  

五,几个概念:

来源 MongoDB面试题问题以及参考答案

8.什么是”mongod“
  mongod是处理MongoDB系统的主要进程。它处理数据请求,管理数据存储,和执行后台管理操作。当我们运行mongod命令意味着正在启动MongoDB进程,并且在后台运行。

9."mongod"参数有什么
  传递数据库存储路径,默认是"/data/db"
  端口号 默认是 "27017"
10.什么是"mongo"
  它是一个命令行工具用于连接一个特定的mongod实例。当我们没有带参数运行mongo命令它将使用默认的端口号和localhost连接

 

 

 

 

 

.

MongoDB的安装,mongod和mongo的区别

标签:数据存储   auth   进程   command   rms   成功   agg   reset   orm   

人气教程排行