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

部分 V. MongoDB

目录

41. Install 安装MongoDB
41.1. CentOS 8 Stream
41.2. MacOS 安装 MongoDB
41.3. 二进制tar包安装
41.4. Ubuntu MongoDB
41.5. CentOS 7 MongoDB
41.6. 从官网安装最新版本的 MongoDB 3.4
41.6.1. Server
41.6.2. Client
41.6.3. 工具
41.7. MongoDB + Hadoop
41.8. OSCM 一键安装 MongoDB 4.0.2
41.9. Replication
41.10. Drivers
41.10.1. Using MongoDB in PHP
42. MongoDB 管理
42.1. Security and Authentication
42.1.1. 超级管理员
42.1.2. 数据库访问用户
42.1.3. 数据库监控用户
42.1.4. 删除用户
42.1.5. 更新角色
42.2. 4.0早期旧版本
43. 命令工具
43.1. mongo - MongoDB Shell
43.1.1. eval
43.1.2. help
43.1.3. 登陆认证
43.1.4. 管道操作
43.2. mongodump - Backup
43.2.1. 本地备份
43.2.2. 远程备份
43.3. mongorestore
43.3.1. 本地恢复
43.3.2. 远程恢复
43.3.3. filter
43.4. mongostat
43.5. mongotop
43.6. mongofiles - Browse and modify a GridFS filesystem.
43.6.1. list 浏览文件
43.6.2. put 上传文件
43.6.3. get 下载
43.6.4. delete 删除
44. MongoDB Shell
44.1. shutdownServer
44.2. show 查看命令
44.2.1. show dbs
44.2.2. show collections
44.2.3. show users
44.2.4. show profile
44.3. 切换数据库
44.4. Collection 管理
44.4.1. 创建 Collection
44.4.2. 删除 collection
44.4.3. 删除字段
44.5. save
44.6. insert
44.7. update
44.7.1. multi 更新所有数据
44.7.2. upsert 更新,如果不存在则插入数据
44.7.3. updateMany 更新集合中的所有数据
44.8. remove
44.8.1. 删除条件使用 _id
44.9. count()
44.10. 查询
44.10.1. find() MongoDB 2.x
44.10.2. find() MongoDB 3.x
44.10.3. group()
44.11. aggregate
44.11.1. project
44.11.2. groupby + sum
44.12. Indexes 索引
44.12.1. 查看索引
44.12.2. 创建索引
44.12.3. 删除索引
44.12.4. 唯一索引
44.12.5. 复合索引
44.12.6. 稀疏索引
44.13. Map-Reduce
44.13.1. 使用 Map-Reduce 统计Web 服务器 access.log 日志文件
44.14. 内嵌对象
44.14.1. Array / List 列表类型
44.15. Javascript 脚本
45. Mongo Admin UI
45.1. RockMongo
45.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/