db.help()

2018-03-03T18:40:52.308+0800 I CONTROL  [initandlisten] 
2018-03-03T18:40:52.308+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-03-03T18:40:52.308+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-03-03T18:40:52.308+0800 I CONTROL  [initandlisten] 
2018-03-03T18:40:52.308+0800 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 3821 processes, 65536 files. Number of processes should be at least 32768 : 0.5 times number of files.
2018-03-03T18:40:52.308+0800 I CONTROL  [initandlisten] 
> show  tables;
> show dbs;
admin   0.000GB
config  0.000GB
local   0.000GB
> du
2018-03-03T19:27:34.145+0800 E QUERY    [thread1] ReferenceError: du is not defined :
@(shell):1:1
> j
2018-03-03T19:28:46.003+0800 E QUERY    [thread1] ReferenceError: j is not defined :
@(shell):1:1
> use  admin
switched to db admin
> show tables;
system.version
> use local
switched to db local
> show tables;
startup_log
> use config
switched to db config
> show tables;
system.sessions
> show collections;
system.sessions
> 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)
db.commandHelp(name) returns the help for the command
db.copyDatabase(fromdb, todb, fromhost)
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.Linux 端启动 MongoDB 服务; 2.客户端连接数据库。 DOS(Windows)端启动 MongoDB 服务 配置环境变量 在电脑->属性->环境变量->Path中添加 MongoDB 安装路径(根据自己的安装路径添加),如图 1 所示: 图 1 启动服务并进行相关配置; mongod.exe --bind_ip 127.0.0.1 --logpath D:\MongoDB\dblog\mongodb.log --logappend --dbpath D:\MongoDB\db --port 27017 --service bind_ip :绑定服务 IP,绑定127.0.0.1,则只能本机访问,不指定默认本地所有 IP ; logpath :配置日志存放的位置; logappend :日志使用追加的方式; dbpath :配置数据存放的位置; port :配置端口号,27017是默认端口; service :以服务方式启动,即后台启动。 服务可以按照以上的方式,使用不同的端口、日志文件和数据存放位置启动多个。 Linux 端启动 MongoDB 服务 (平台已经帮你配置好环境,如果是在本地环境练习,请安装并配置好 MongoDB)启动 MongoDB 服务,要准备数据存放位置,日志文件和配置文件。 数据存放位置 在 /data 路径下创建文件夹 db_test 来存放 MongoDB 服务的数据。 cd /data #进入data路径 mkdir db_test #创建db文件夹 日志文件 在 /logs 路径下创建文件夹 mongo 存放日志文件 mongod.log(文件不用创建,到时候会自动生成,但路径即文件夹必须提前创建好)。 mkdir /logs #创建/logs路径 cd /logs #进入log路径 mkdir mongo #创建mongo文件夹 配置文件 在 /etc/mongod(没有路径就创建)路径下新建配置文件 mongod.conf,使用配置文件启动 MongoDB 服务(把命令写入配置文件,以后启动服务就不用再输入一长串的命令,直接启动配置文件即可)。 mongod.conf 内容如图2所示: 图 2 以上工作准备完成,便可以开启服务了,配置文件启动命令如下(在命令行中输入): mongod -f /etc/mongod/mongod.conf 启动客户端 不管是哪种平台,客户端的操作都基本相同。输入命令 mongo --port 27017 连接客户端(MongoDB 默认的连接方式无需输入用户名和密码,port 端口根据你服务启动的端口连接),如图3所示: 图 3 如图出现最后一行的>符号,说明连接成功。 help 帮助文档 MongoDB 我们刚接触,并不了解怎么使用命令进行操作,这时候就可以用 help 帮助文档了,里面有 MongoDB 的所有操作命令。 查看 MongoDB 支持哪些命令help; 查询当前数据库支持的方法:db.help(); 查询集合支持哪些方法:db.集合名.help()。 更多详细说明,可以查看其文档: MongoDB 官方文档 MongoDB 中文文档 编程要求 根据提示,在右侧命令行(Linux 环境)进行操作: 在 /data 路径下创建文件夹 mydb 来存放 MongoDB 服务的数据; 在 /logs 路径下创建文件夹 mymongo 存放日志文件 mongod.log; 在 /etc/mymongod 路径下新建配置文件 mongod.conf,使用配置文件启动 MongoDB,连接端口号设置为 27020; 使用命令通过配置文件启动服务。 测试说明 点击测评后,平台会尝试连接端口为27020的客户端, 连接成功,输出: MongoDB连接成功! 连接失败,输出: MongoDB连接失败~ 如果出现图4的错误,请点击图5标识的右侧代码区域相应的“重置命令行”按钮,重置环境即可。 图 4
最新发布
05-28
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值