A preliminary study on MongoDB Gridfs

Source: Internet
Author: User
Tags syslog

Simple Introduction using Gridfs:

List files:

[Email protected] ~]# mongofiles list
Connected to:127.0.0.1



No files exist at this time.


Upload file:

[Email protected] ~]# Mongofiles put install.log-d Libraray
Connected to:127.0.0.1
Added file: {_id:objectid (' 5616b8c4f1403ca60b0999d0 '), FileName: "Install.log", chunksize:261120, Uploaddate:new Date (1444329668441), MD5: "c7d8a01a077940859e773b7770d2e07e", length:9458}
done!


List the uploaded files again:

[Email protected] ~]# mongofiles list-d Libraray
Connected to:127.0.0.1
Install.log 9458



To view data in MongoDB:

[Email protected] ~]# MONGO Libraray
MongoDB Shell version:2.6.11
Connecting To:libraray
> Db.fs.files.find ()
{"_id": ObjectId ("5616b8c4f1403ca60b0999d0"), "filename": "Install.log", "chunkSize": 261120, "uploaddate": Isodate (" 2015-10-08t18:41:08.441z ")," MD5 ":" c7d8a01a077940859e773b7770d2e07e "," Length ": 9458}
>
Specify ID:

> Db.fs.files.find ({"_id": ObjectId ("5616b8c4f1403ca60b0999d0")})
{"_id": ObjectId ("5616b8c4f1403ca60b0999d0"), "filename": "Install.log", "chunkSize": 261120, "uploaddate": Isodate (" 2015-10-08t18:41:08.441z ")," MD5 ":" c7d8a01a077940859e773b7770d2e07e "," Length ": 9458}


> db.fs.chunks.find ({},{"data": 0})
{"_id": ObjectId ("5616b8c4d2b40c73cbf811c8"), "files_id": ObjectId ("5616b8c4f1403ca60b0999d0"), "n": 0}


Search for files:

[email protected] ~]# cat Testfile
Hello ABC

[Email protected] ~]# Mongofiles put testfile-d Libraray
Connected to:127.0.0.1
Added file: {_id:objectid (' 5616bd093be512c2e45d0351 '), FileName: "Testfile", chunksize:261120, Uploaddate:new Date (14 44330761770), MD5: "563427968920fcf5177c6753bd6cbae3", length:10}
done!

[Email protected] ~]# Mongofiles search test-d Libraray
Connected to:127.0.0.1
Testfile 10

(seemingly unable to search the file content!!!) )

To delete a file:

[Email protected] ~]# mongofiles Delete testfile-d Libraray
Connected to:127.0.0.1
done!
[Email protected] ~]# Mongofiles search test-d Libraray
Connected to:127.0.0.1

Get file:

[[email protected] ~]# ls
Anaconda-ks.cfg Install.log install.log.syslog Modb testfile
[Email protected] ~]# RM-RF Install.log
[[email protected] ~]# mongofiles get install.log-d Libraray
Connected to:127.0.0.1
Done Write To:install.log
[[email protected] ~]# ls
Anaconda-ks.cfg Install.log install.log.syslog Modb testfile


Test upload Large files:

[Email protected] ~]# du-h 2290944.zip
3.2G 2290944.zip

[Email protected] ~]# Mongofiles put 2290944.zip-d Libraray
Connected to:127.0.0.1
Added file: {_id:objectid (' 5616c158bfb7f87bb8e48d44 '), FileName: "2290944.zip", chunksize:261120, Uploaddate:new Date (1444331976703), MD5: "6FC45DD991D89DB358194EBA0B565F30", length:3372909855}
done!


> Db.fs.chunks.find ({"files_id": ObjectId ("5616c158bfb7f87bb8e48d44")},{"data": 0}). sort ({n:-1}). Limit (1)
{"_id": ObjectId ("5616c1a2d2b40c73cbf84467"), "files_id": ObjectId ("5616c158bfb7f87bb8e48d44"), "n": 12917}


There are a total of 12,918 chunk (the first chunk is 0), the 12918x261120 size is: 3373148160 can save this file, in other machines to retrieve it back to success.


This article is from the "Technical Blog" blog, please be sure to keep this source http://raytech.blog.51cto.com/7602157/1701254

A preliminary study on MongoDB Gridfs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.