Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 知乎專欄 | 視頻教程 | About

13.6. mongofiles - Browse and modify a GridFS filesystem.

13.6.1. list 瀏覽檔案

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

			

13.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

13.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
			

13.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