博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MongoDB数据库基本操作
阅读量:7260 次
发布时间:2019-06-29

本文共 2800 字,大约阅读时间需要 9 分钟。

查看当前数据库

MongoDB shell version:
1.8
.
1
connecting to:test
>
 db
test

 

查看全部数据库列表

>
show dbs
ChatRoom    0.03125GB
admin       (empty)
local       (empty)

 

切换数据库

>
use ChatRoom
switched to db ChatRoom
>
db
ChatRoom

 

删除数据库

>
db
ChatRoom
>
show dbs
ChatRoom    0.03125GB
admin       (empty)
local       (empty)
>
db.dropDatabase()
{
"
dropped
"
:
"
ChatRoom
"
,
"
ok
"
:
1
}
>
show dbs
admin       (empty)
local       (empty)

 

 MongoDB帮助主题help

> help
        db.help()                    help on db methods
        db.mycoll.help()             help on collection methods
        rs.help()                    help on replica set methods
        help connect                 connecting to a db help
        help admin                   administrative help
        help misc                    misc things to know
        help mr                      mapreduce help
        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
        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 furtheriterate
        DBQuery.shellBatchSize 
=
 x   set default number of items to display on shell
        exit                         quit the mongo shell

 

>
 db.help()
DB methods:
        db.addUser(username, password[, readOnly
=
false])
        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.currentOp() displays the current operation 
in
 the db
        db.dropDatabase()
        db.eval(func, args) run code server
-
side
        db.getCollection(cname) same as db[
'
cname
'
or
 db.cname
        db.getCollectionNames()
        db.getLastError() 
-
 just returns the err msg string
        db.getLastErrorObj() 
-
 
return
 full status object
        db.getMongo() get the server connection object
        db.getMongo().setSlaveOk() allow this connection to read 
from
 the nonmaster member of a replica pair
        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.isMaster() check replica primary status
        db.killOp(opid) kills the current operation 
in
 the db
        db.listCommands() lists all the db commands
        db.printCollectionStats()
        db.printReplicationInfo()
        db.printSlaveReplicationInfo()
        db.printShardingStatus()
        db.removeUser(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.setProfilingLevel(level,
<
slowms
>
) 0
=
off 
1
=
slow 
2
=
all
        db.shutdownServer()
        db.stats()
        db.version() current version of the server
        db.getMongo().setSlaveOk() allow queries on a replication slave server

转载于:https://www.cnblogs.com/libingql/archive/2011/06/08/2075268.html

你可能感兴趣的文章
CelloCloud电子邮件云安全服务
查看>>
logrotate切割nginx日志
查看>>
钉科技:决胜网戴政 让天下没有难找的班
查看>>
首届中国数据标准化及治理大会落幕 大数据基础能力建设方兴未艾
查看>>
powercat工具详细分析
查看>>
如何避免IPv6“友邻发现”威胁?
查看>>
探索阿里巴巴如何打造共享服务中台的稳定性——走进《企业IT架构转型之道》系列3...
查看>>
从大数据中“提炼”出商业见解,企业还有很多工作要做
查看>>
《并行计算的编程模型》一3.7.5 收集
查看>>
CA增强应用管理和监控的敏捷性 促进DevOps加快软件发布速度
查看>>
圆桌对话:新技术时代下IT管理的机遇
查看>>
云原生(Cloud Native)- 移动App研发新范式
查看>>
log4j2配置文件log4j2.xml解析
查看>>
我与云计算大会的三天
查看>>
高通发布两款物联网旗舰WiFi芯片
查看>>
绿盟科技Techworld 2017网络安全智能化 机器学习成亮点
查看>>
摩托罗拉系统完成对Kodiak Networks收购
查看>>
美国网络监听系统曝光:服务器遍布世界
查看>>
数据加密,国际软件标准,零封全球黑客,书生云20年庆典上的看点解密
查看>>
如何在Windows 10下轻松开启RS2 UWP版文件资源管理器
查看>>