Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

部分 II. MongoDB

目录

10. Install 安装MongoDB
10.1. CentOS 8 Stream
10.2. MacOS 安装 MongoDB
10.3. 二进制tar包安装
10.4. Ubuntu MongoDB
10.5. CentOS 7 MongoDB
10.6. 从官网安装最新版本的 MongoDB 3.4
10.6.1. Server
10.6.2. Client
10.6.3. 工具
10.7. MongoDB + Hadoop
10.8. OSCM 一键安装 MongoDB 4.0.2
10.9. Replication
10.10. Drivers
10.10.1. Using MongoDB in PHP
11. MongoDB 管理
11.1. Security and Authentication
11.1.1. 超级管理员
11.1.2. 数据库访问用户
11.1.3. 数据库监控用户
11.1.4. 删除用户
11.1.5. 更新角色
11.2. 4.0早期旧版本
12. 命令工具
12.1. mongo - MongoDB Shell
12.1.1. eval
12.1.2. help
12.1.3. 登陆认证
12.1.4. 管道操作
12.2. mongodump - Backup
12.2.1. 本地备份
12.2.2. 远程备份
12.3. mongorestore
12.3.1. 本地恢复
12.3.2. 远程恢复
12.3.3. filter
12.4. mongostat
12.5. mongotop
12.6. mongofiles - Browse and modify a GridFS filesystem.
12.6.1. list 浏览文件
12.6.2. put 上传文件
12.6.3. get 下载
12.6.4. delete 删除
13. MongoDB Shell
13.1. shutdownServer
13.2. show 查看命令
13.2.1. show dbs
13.2.2. show collections
13.2.3. show users
13.2.4. show profile
13.3. 切换数据库
13.4. Collection 管理
13.4.1. 创建 Collection
13.4.2. 删除 collection
13.4.3. 删除字段
13.5. save
13.6. insert
13.7. update
13.7.1. multi 更新所有数据
13.7.2. upsert 更新,如果不存在则插入数据
13.7.3. updateMany 更新集合中的所有数据
13.8. remove
13.8.1. 删除条件使用 _id
13.9. count()
13.10. 查询
13.10.1. find() MongoDB 2.x
13.10.2. find() MongoDB 3.x
13.10.3. group()
13.11. aggregate
13.11.1. project
13.11.2. groupby + sum
13.12. Indexes 索引
13.12.1. 查看索引
13.12.2. 创建索引
13.12.3. 删除索引
13.12.4. 唯一索引
13.12.5. 复合索引
13.12.6. 稀疏索引
13.13. Map-Reduce
13.13.1. 使用 Map-Reduce 统计Web 服务器 access.log 日志文件
13.14. 内嵌对象
13.14.1. Array / List 列表类型
13.15. Javascript 脚本
14. Mongo Admin UI
14.1. RockMongo
14.2. MongoVUE

http://www.mongodb.org/

1. FAQ

1.1. MongoDB 3.x 启用认证后恢复数据库需指定 collection

			# mongorestore -u yourdb dump/
			Enter password:

			2017-06-09T11:55:58.566+0800 Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.
		
			# mongorestore -u yourdb -d yourdb dump/yourdb
		

1.2. MongoDB 2.x 早期版本用户管理

		
> use admin
switched to db admin
> db.addUser('neo','chen')
{
        "user" : "neo",
        "readOnly" : false,
        "pwd" : "68ace374737253d87e0ec91d4fcb673d"
}

> db.system.users.find()
{ "_id" : ObjectId("4c481404b9db6474d2fcb76f"), "user" : "neo", "readOnly" : false, "pwd" : "68ace374737253d87e0ec91d4fcb673d" }

> db.auth('neo','chen')
1		
		
		

1.3. Failed: netkiller.assets: error reading database: command listCollections requires authentication

		
[root@ecs-3705 ~]# mongorestore dump/
2018-11-05T11:48:08.981+0800	preparing collections to restore from
2018-11-05T11:48:08.982+0800	Failed: netkiller.assets: error reading database: command listCollections requires authentication			
		
		

需要认证,请使用 -u 用户名 -p 密码 -d 数据库 来恢复

		
[root@netkiller ~]# mongorestore -h 127.0.0.1 -u netkiller -p netkiller -d netkiller  dump/netkiller/