【MongoDB学习笔记4】MongoDB管理客户端和创建数据库
MongoDB管理客户端背后是一个JavaScript Shell,是一个完整的JavaScript解释器,用”mongo”命令登入;
进入后进入默认的test数据库,可以用db命令查看当前的所连接的数据库:
[root@localhost ~]# mongo MongoDB shell version: 2.6.6 connecting to: test > db test >
输入help来查找可用的命令:
> help db.help() help on db methods db.mycoll.help() help on collection methods sh.help() harding 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 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 >
MongoDB没有显示的创建数据库的命令和删除的数据库的命令,创建数据库用use即可;
创建blog的数据库:
> use blog switched to db blog
插入一个集合和文档:
> db.post.insert({"geeting":3}); WriteResult({ "nInserted" : 1 })
查看创建的数据库和集合:
> show dbs admin (empty) blog 0.078GB local 0.078GB > show collections post system.indexes
删除数据库
> db.dropDatabase(); { "dropped" : "blog", "ok" : 1 } > show dbs admin (empty) local 0.078GB
本文出自 “缘随心愿” 博客,请务必保留此出处http://281816327.blog.51cto.com/907015/1598286
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。