- 查看版本
mongod --version
- 从 4.4 版本开始 db 和 tool 分离了
历史
4.4
4.2 2019
4.0 2018
3.6 2017
YUM方式安装
安装
1 | vi /etc/yum.repos.d/mongodb-org-4.4.repo |
启动
1 | service mongod start |
To prevent unintended upgrades
1 | vi /etc/yum.conf |
auto bootchkconfig mongod on
Tarball方式安装
1 | sudo yum install libcurl openssl |
启动
1 | mkdir -p /var/lib/mongo |
使用
登录
1 | mongo --host ip |
监控
1 | mongostat |
数据库
1 | show dbs |
文档
1 | show collections |
查询文档
1 | db.collection.find( {} ).limit(5) |
插入
1 | db.test.insert({ |
更新
1 | db.collection.updateOne() |
删除
1 | db.collection.deleteOne() |
排序
1 | db.collection.sort({'exec_time': -1}).count() |
索引
1 | db.collection.createIndex({'exec_time': -1}) |
参考
Install MongoDB Community on Red Hat or CentOS using .tgz Tarball
Install MongoDB Community Edition on Red Hat Enterprise or CentOS Linux