mongodb学习文档

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

MongoDB学习文档v0.212016/9/18mongodb学习文档v0.212/55mongodb学习文档1.安装mongodb1.1系统环境#cat/etc/redhat-releaseRedHatEnterpriseLinuxServerrelease5.8(Tikanga)1.2创建组和用户#groupaddmongodba#useraddmongodb-p123321-gmongodba1.3下载、解压、移动安装包#cd/tmp#tar-zxvfmongodb-linux-x86_64-rhel55-3.2.9.tgz#mkdir-p/u01/mongodb#mvmongodb-linux-x86_64-rhel55-3.2.9//u01/mongodb/#chownmongodb:mongodba-R/u01/mongodb/1.4设置环境变量#vi/etc/profile添加如下内容#2016.09.13addmongodb#mongodbvariablesstartexportMONGODB_HOME=/u01/mongodb/mongodb-linux-x86_64-rhel55-3.2.9exportPATH=$PATH:$MONGODB_HOME/bin#mongodbvariablesend#source/etc/profile1.5创建数据库目录#mkdir-p/data/db#chownmongodb:mongodba-R/data/dbmongodb学习文档v0.213/551.6Mongodb概念解析SQL术语/概念MongoDB术语/概念解释/说明databasedatabase数据库tablecollection数据库表/集合rowdocument数据记录行/文档columnfield数据字段/域indexindex索引tablejoins表连接,MongoDB不支持primarykeyprimarykey主键,MongoDB自动将_id字段设置为主键数据库名可以是满足以下条件的任意UTF-8字符串不能是空字符串(“”)不得含义空格、.、$、/、\和\0(空字符)应全部小写最多64个字节有一些数据库名是保留的,可以直接访问这些有特殊作用的数据库admin:从权限的角度看,这是“root”数据库,要是将一个用户添加到这个数据库,这个用户自动继承所有数据库的权限,一些特定的服务器端命令也只能从这个数据库运行,比如列出所有的数据库或者关闭服务器local:这个数据永远不会被复制,可以用于存储限于本地单台服务器的任意集合config:当Mongodb用于分片设置时,config数据库在内部使用,用于保存分片的相关信息文档键的命名规范键不能含有空字符.和$有特别的意义,只有在特定的环境下才能使用以下划线开头的键是保留的(不是严格要求的)mongodb学习文档v0.214/55合法的集合名集合名不能是空字符串集合名不能含有空字符集合名不能以”system.”开头,这是为系统集合保留的前缀用户创建的集合名字不能含有保留字符,有些驱动程序的支持在集合里面包含,这是因为某些系统生成的集合中包含该字符,除非要访问这种系统创建的集合,否则千万不要在名字里出现$2.启动和连接mongodb2.1运行mongodb服务#su-mongodb$cd/u01/mongodb/mongodb-linux-x86_64-rhel55-3.2.9/bin$./mongod2016-09-28T10:05:01.840+0800ICONTROL[initandlisten]MongoDBstarting:pid=9759port=27017dbpath=/data/db64-bithost=TRAMOMAP2016-09-28T10:05:01.840+0800ICONTROL[initandlisten]dbversionv3.2.92016-09-28T10:05:01.840+0800ICONTROL[initandlisten]gitversion:22ec9e93b40c85fc7cae7d56e7d6a02fd811088c2016-09-28T10:05:01.840+0800ICONTROL[initandlisten]OpenSSLversion:OpenSSL0.9.8e-fips-rhel501Jul20082016-09-28T10:05:01.840+0800ICONTROL[initandlisten]allocator:tcmalloc2016-09-28T10:05:01.840+0800ICONTROL[initandlisten]modules:none2016-09-28T10:05:01.840+0800ICONTROL[initandlisten]buildenvironment:2016-09-28T10:05:01.840+0800ICONTROL[initandlisten]distmod:rhel552016-09-28T10:05:01.840+0800ICONTROL[initandlisten]distarch:x86_642016-09-28T10:05:01.840+0800ICONTROL[initandlisten]target_arch:x86_642016-09-28T10:05:01.840+0800ICONTROL[initandlisten]options:{}2016-09-28T10:05:01.868+0800ISTORAGE[initandlisten]wiredtiger_openconfig:create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),2016-09-28T10:05:27.908+0800IFTDC[initandlisten]Initializingfull-timediagnosticdatacapturewithdirectory'/data/db/diagnostic.data'2016-09-28T10:05:27.917+0800INETWORK[HostnameCanonicalizationWorker]Startinghostnamecanonicalizationworkermongodb学习文档v0.215/552016-09-28T10:05:28.082+0800INETWORK[initandlisten]waitingforconnectionsonport270172.2连接mongodb新打开一个终端,进入mongodb目录$cd$MONGODB_HOME/bin$./mongoMongoDBshellversion:3.2.9connectingto:testWelcometotheMongoDBshell.Forinteractivehelp,typehelp.Formorecomprehensivedocumentation,see://groups.google.com/group/mongodb-userdbtest2.3简单测试插入数据db.mytab.insert({x:15})WriteResult({nInserted:1})查询数据db.mytab.find(){_id:ObjectId(57eb27f2bc910735a5c2af0b),x:15}2.4退出mongodbexitbye2.5关闭mongodb$pkillmongodmongodb学习文档v0.216/552.6mongodbweb界面$./mongod--rest2016-09-28T10:35:12.050+0800ICONTROL[main]**WARNING:--restisspecifiedwithout--httpinterface,2016-09-28T10:35:12.050+0800ICONTROL[main]**enablinghttpinterface2016-09-28T10:35:12.070+0800ICONTROL[initandlisten]MongoDBstarting:pid=9985port=27017dbpath=/data/db64-bithost=TRAMOMAP2016-09-28T10:35:12.070+0800ICONTROL[initandlisten]dbversionv3.2.92016-09-28T10:35:12.070+0800ICONTROL[initandlisten]gitversion:22ec9e93b40c85fc7cae7d56e7d6a02fd811088c2016-09-28T10:35:12.070+0800ICONTROL[initandlisten]OpenSSLversion:OpenSSL0.9.8e-fips-rhel501Jul20082016-09-28T10:35:12.070+0800ICONTROL[initandlisten]allocator:tcmalloc2016-09-28T10:35:12.070+0800ICONTROL[initandlisten]modules:none2016-09-28T10:35:12.070+0800ICONTROL[initandlisten]buildenvironment:2016-09-28T10:35:12.070+0800ICONTROL[initandlisten]distmod:rhel552016-09-28T10:35:12.070+0800ICONTROL[initandlisten]distarch:x86_642016-09-28T10:35:12.070+0800ICONTROL[initandlisten]target_arch:x86_642016-09-28T10:35:12.070+0800ICONTROL[initandlisten]options:{net:{http:{RESTInterfaceEnabled:true,enabled:true}}}2016-09-28T10:35:12.098+0800I-[initandlisten]Detecteddatafilesin/data/dbcreatedbythe'wiredTiger'storageengine,sosettingtheactivestorageengineto'wiredTiger'.2016-09-28T10:35:12.099+0800ISTORAGE[initandlisten]wiredtiger_openconfig:create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpo

1 / 55
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功