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

43.6. mongofiles - Browse and modify a GridFS filesystem.

43.6.1. list 浏览文件

# mongofiles list
connected to: 127.0.0.1
/etc/passwd 2176
/tmp/test1.php 192
			

43.6.2. put 上传文件

# mongofiles put /bin/ls
connected to: 127.0.0.1
added file: { _id: ObjectId('55ee4c68bd053b7418404c53'), filename: "/bin/ls", chunkSize: 261120, uploadDate: new Date(1441680488106), md5: "ca226dd605e91b72e0d2060a6357c28f", length: 109208 }
done!

# mongofiles list
connected to: 127.0.0.1
/etc/passwd 2176
/tmp/test1.php 192
/bin/ls 109208
			

上传指定数据库

# mongofiles put -d images -c img /etc/fstab
connected to: 127.0.0.1
added file: { _id: ObjectId('55ee4d5416377f58d0a9e714'), filename: "/etc/fstab", chunkSize: 261120, uploadDate: new Date(1441680724579), md5: "381185dc0c4807b88406b452b4acc2e8", length: 1067 }
done!

# mongofiles list -d images -c img
connected to: 127.0.0.1
/etc/fstab 1067
			
[提示]collection 参数有 bug 需要注意。

-c img 似乎无效,可能是mongofiles的bug. 使用PHP测试上传是可以指定 collection,并且没有任何问题。

				
# mongofiles put -d images --collection abc /etc/nfsmount.conf
connected to: 127.0.0.1
added file: { _id: ObjectId('55ee4f5ef4b26bc3189dc8a5'), filename: "/etc/nfsmount.conf", chunkSize: 261120, uploadDate: new Date(1441681246083), md5: "ce3b9fee8612087cbb69d46db34ce8ec", length: 3605 }
done!

# mongofiles -d images --collection abc list
connected to: 127.0.0.1
/etc/fstab	1067
/etc/passwd	2555
/etc/goaccess.conf	6956
/etc/krb5.conf	449
/etc/nfsmount.conf	3605

# mongo images
> show collections;
abc.fs.chunks
abc.fs.files
fs.chunks
fs.files
system.indexes
>

> db.abc.fs.files.find();
>
				
				

使用 --collection 参数可以看到abc已经创建,但我们去db.abc.fs.files.find();发现里面没有任何数据,文件仍然被上传到 abc.fs.files

43.6.3. get 下载

如果 /tmp/test123 存在则会覆盖

# mongofiles get /tmp/test123
connected to: 127.0.0.1
done write to: /tmp/test123
			

-l 指定路径,相当于另存。

# mongofiles get /tmp/test123 -l /tmp/aabbcc
connected to: 127.0.0.1
done write to: /tmp/aabbcc
			

43.6.4. delete 删除

# mongofiles list
connected to: 127.0.0.1
/etc/passwd 2176
/tmp/test1.php 192
/bin/ls 109208
/tmp/test123 6

# mongofiles delete /tmp/test123
connected to: 127.0.0.1
done!

# mongofiles list
connected to: 127.0.0.1
/etc/passwd 2176
/tmp/test1.php 192
/bin/ls 109208