标签:mongodb总结
0.安装mongodb:
1)curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.4.tgz
2)tar -zxvf mongodb-linux-x86_64-2.6.4.tgz
3)mkdir -p mongodb
cp -R mongodb-linux-x86_64-2.6.4/ mongodb
4)export PATH=<mongodb-install-directory>/bin:$PATH
mongod --dbpath=/home/app/mongodb/mongodbdata/ -- logpath=/home/app/mongodb/log/mongodb.log --logappend&
2.mongo
3.use admin
4.db.addUser(‘mongouser‘,‘123456!‘);
5.kill
6.mongod --auth --dbpath=/home/app/mongodb/mongodbdata/ --
logpath=/home/app/mongodb/log/mongodb.log --logappend&
7.创建数据库operationlog,创建collections
operationlog,
oparticlelog,
optopiclog,
oploginlog
8.创建索引:
db.operationlog.ensureIndex({ "userId" : 1, "updateTime" : -1 },{ "name" : "oplog_userid_index" });
db.oparticlelog.ensureIndex({ "userId" : 1, "updateTime" : -1 },{ "name" : "opdoclog_userid_index" });
db.oparticlelog.ensureIndex({ "articleId" : 1, "updateTime" : -1 },{ "name" : "opdoclog_docid_index" });
db.oploginlog.ensureIndex({ "userId" : 1, "updateTime" : -1 },{ "name" : "oploginlog_userid_index" });
db.optopiclog.ensureIndex({ "userId" : 1, "updateTime" : -1 },{ "name" : "optopicid_userid_index" });
db.optopiclog.ensureIndex({ "topicId" : 1, "updateTime" : -1 },{ "name" : "optopicidlog_topicid_index" });
9.给operationlog添加用户,
1)mongo
2)use admin;
3)db.auth(‘mongouser‘,‘123456!‘);
4)use operationlog
5)db.addUser(‘mongouser‘,‘123456!‘);
10.其它命令:
mongo
use operationlog;
db.auth(‘mongouser‘,‘123456!‘);
show dbs:显示数据库列表
show collections:显示当前数据库中的集合(类似关系数据库中的表)
show users:显示用户
db.optopiclog.count(); 查看集合总数据量
exit; 退出
11.查看删除日志功能:
mongo
use operationlog;
db.auth(‘mongouser‘,‘123456!‘);
1) 创建表:db.createCollection("opdellog");
2)创建索引:
db.opdellog.ensureIndex({ "userId" : 1, "updateTime" : -1 },{ "name" : "opdellog_userid_index" });
db.opdellog.ensureIndex({ "articleId" : 1, "updateTime" : -1 },{ "name" : "opdellog_docid_index" });
db.opdellog.ensureIndex({ "articleOrModelName" : 1, "updateTime" : -1 },{ "name" : "opdellog_docname_index" });
3)查看某个表上的所有索引
db.opdellog.getIndexes();
本文出自 “宁静致远” 博客,谢绝转载!
标签:mongodb总结
原文地址:http://woodpecker.blog.51cto.com/2349932/1865025