首页 / 数据库 / MySQL / MongoDB常用操作命令整理
mongodb操作命令(注意所有db.开头命令,请先使用use到指定db再操作)
连接操作数据库:
/usr/local/mongodb-3.0.4/bin/mongo 192.168.6.118:30000/admin添加分片服务器:
db.runCommand({"addshard":"192.168.6.118:27017"})设置分片数据库:
db.runCommand({"enablesharding": "qiaodazhao"})
db.runCommand({"enablesharding": "testdb"})使用数据库:
use qiaodazhao设置表分片基于字段hash:
sh.shardCollection("qiaodazhao.resume_meta_data",{_id:"hashed"})
sh.shardCollection("testdb.resumetemp",{_id:"hashed"})设置表分片基于字段(注意以下两种方式作用相同):
db.runCommand({"shardcollection":"qiaodazhao.things", "key":{"_id":1}})
sh.shardCollection("qiaodazhao.things",{_id:1})打印数据库分片信息:
db.printShardingStatus()打印服务器信息:
db.serverStatus()表格数据总量统计:
db.table.count()创建表索引:
db.resume_meta_data.ensureIndex({"org_name":1},{"background":true})查看表索引:
db.resume_meta_data.getIndexes()MongoDB 3.0 正式版发布下载 http://www.linuxidc.com/Linux/2015-03/114414.htmCentOS编译安装MongoDB http://www.linuxidc.com/Linux/2012-02/53834.htmCentOS 编译安装 MongoDB与mongoDB的php扩展 http://www.linuxidc.com/Linux/2012-02/53833.htmCentOS 6 使用 yum 安装MongoDB及服务器端配置 http://www.linuxidc.com/Linux/2012-08/68196.htmUbuntu 13.04下安装MongoDB2.4.3 http://www.linuxidc.com/Linux/2013-05/84227.htmMongoDB入门必读(概念与实战并重) http://www.linuxidc.com/Linux/2013-07/87105.htmUbunu 14.04下MongoDB的安装指南 http://www.linuxidc.com/Linux/2014-08/105364.htm《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF] http://www.linuxidc.com/Linux/2012-07/66735.htmNagios监控MongoDB分片集群服务实战 http://www.linuxidc.com/Linux/2014-10/107826.htm基于CentOS 6.5操作系统搭建MongoDB服务 http://www.linuxidc.com/Linux/2014-11/108900.htmMongoDB 的详细介绍:请点这里
MongoDB 的下载地址:请点这里本文永久更新链接地址