Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

部分 IV. MongoDB

目录

35. Install 安装MongoDB
35.1. CentOS 8 Stream
35.2. MacOS 安装 MongoDB
35.3. 二进制tar包安装
35.4. Ubuntu MongoDB
35.5. CentOS 7 MongoDB
35.6. 从官网安装最新版本的 MongoDB 3.4
35.6.1. Server
35.6.2. Client
35.6.3. 工具
35.7. MongoDB + Hadoop
35.8. OSCM 一键安装 MongoDB 4.0.2
35.9. Replication
35.9.1. Master
35.9.2. Slave
35.9.3. 测试
35.10. Drivers
35.10.1. Using MongoDB in PHP
36. MongoDB 管理
36.1. Security and Authentication
36.1.1. 超级管理员
36.1.2. 数据库访问用户
36.1.3. 数据库监控用户
36.1.4. 删除用户
36.1.5. 更新角色
36.2. 4.0早期旧版本
37. 命令工具
37.1. mongo - MongoDB Shell
37.1.1. eval
37.1.2. help
37.1.3. 登陆认证
37.1.4. 管道操作
37.2. mongodump - Backup
37.2.1. 本地备份
37.2.2. 远程备份
37.3. mongorestore
37.3.1. 本地恢复
37.3.2. 远程恢复
37.3.3. filter
37.4. mongostat
37.5. mongotop
37.6. mongofiles - Browse and modify a GridFS filesystem.
37.6.1. list 浏览文件
37.6.2. put 上传文件
37.6.3. get 下载
37.6.4. delete 删除
38. MongoDB Shell
38.1. shutdownServer
38.2. show 查看命令
38.2.1. show dbs
38.2.2. show collections
38.2.3. show users
38.2.4. show profile
38.3. 切换数据库
38.4. Collection 管理
38.4.1. 创建 Collection
38.4.2. 删除 collection
38.4.3. 删除字段
38.5. save
38.6. insert
38.7. update
38.7.1. multi 更新所有数据
38.7.2. upsert 更新,如果不存在则插入数据
38.7.3. updateMany 更新集合中的所有数据
38.8. remove
38.8.1. 删除条件使用 _id
38.9. count()
38.10. 查询
38.10.1. find() MongoDB 2.x
38.10.2. find() MongoDB 3.x
38.10.3. group()
38.11. aggregate
38.11.1. project
38.11.2. groupby + sum
38.12. Indexes 索引
38.12.1. 查看索引
38.12.2. 创建索引
38.12.3. 删除索引
38.12.4. 唯一索引
38.12.5. 复合索引
38.12.6. 稀疏索引
38.13. Map-Reduce
38.13.1. 使用 Map-Reduce 统计Web 服务器 access.log 日志文件
38.14. 内嵌对象
38.14.1. Array / List 列表类型
38.15. Javascript 脚本
39. Mongo Admin UI
39.1. RockMongo
39.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/