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

部分 V. MongoDB

目录

43. Install 安装MongoDB
43.1. CentOS 8 Stream
43.2. MacOS 安装 MongoDB
43.3. 二进制tar包安装
43.4. Ubuntu MongoDB
43.5. CentOS 7 MongoDB
43.6. 从官网安装最新版本的 MongoDB 3.4
43.6.1. Server
43.6.2. Client
43.6.3. 工具
43.7. MongoDB + Hadoop
43.8. OSCM 一键安装 MongoDB 4.0.2
43.9. Replication
43.9.1. Master
43.9.2. Slave
43.9.3. 测试
43.10. Drivers
43.10.1. Using MongoDB in PHP
44. MongoDB 管理
44.1. Security and Authentication
44.1.1. 超级管理员
44.1.2. 数据库访问用户
44.1.3. 数据库监控用户
44.1.4. 删除用户
44.1.5. 更新角色
44.2. 4.0早期旧版本
45. 命令工具
45.1. mongo - MongoDB Shell
45.1.1. eval
45.1.2. help
45.1.3. 登陆认证
45.1.4. 管道操作
45.2. mongodump - Backup
45.2.1. 本地备份
45.2.2. 远程备份
45.3. mongorestore
45.3.1. 本地恢复
45.3.2. 远程恢复
45.3.3. filter
45.4. mongostat
45.5. mongotop
45.6. mongofiles - Browse and modify a GridFS filesystem.
45.6.1. list 浏览文件
45.6.2. put 上传文件
45.6.3. get 下载
45.6.4. delete 删除
46. MongoDB Shell
46.1. shutdownServer
46.2. show 查看命令
46.2.1. show dbs
46.2.2. show collections
46.2.3. show users
46.2.4. show profile
46.3. 切换数据库
46.4. Collection 管理
46.4.1. 创建 Collection
46.4.2. 删除 collection
46.4.3. 删除字段
46.5. save
46.6. insert
46.7. update
46.7.1. multi 更新所有数据
46.7.2. upsert 更新,如果不存在则插入数据
46.7.3. updateMany 更新集合中的所有数据
46.8. remove
46.8.1. 删除条件使用 _id
46.9. count()
46.10. 查询
46.10.1. find() MongoDB 2.x
46.10.2. find() MongoDB 3.x
46.10.3. group()
46.11. aggregate
46.11.1. project
46.11.2. groupby + sum
46.12. Indexes 索引
46.12.1. 查看索引
46.12.2. 创建索引
46.12.3. 删除索引
46.12.4. 唯一索引
46.12.5. 复合索引
46.12.6. 稀疏索引
46.13. Map-Reduce
46.13.1. 使用 Map-Reduce 统计Web 服务器 access.log 日志文件
46.14. 内嵌对象
46.14.1. Array / List 列表类型
46.15. Javascript 脚本
47. Mongo Admin UI
47.1. RockMongo
47.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/