There are two ways to store files in Mongodb in the GridFSB mode: 1. Command Line files2 and client-side driver programming (using Java as an example)
There are two ways to store files in Mongodb in the GridFSB mode: 1. Command Line program files 2. client-side driver programming (using Java as an example)
There are two ways to store files in Mongodb in the GridFSB mode: 1. Command Line program files 2. client-side driver programming (using Java as an example)
Related reading:
MongoDB cluster configuration (sharding with replica set)
Add a shard replica set when MongoDB is running
1. Command Line Program Files
You can insert file data to the Mongodb database under the command line by running the command 'cmdfiles.exe 'command in the bindirectory. The preceding four shards are used as an example to describe the simulated Windows Cluster of three replica sets, three configsevers, and one route node.
D:/mongodb-win32-i386-1.8.0/bin> export files.exe-host 127.0.0.1: 50000-d wlb put into dump.exe
Connected to: 127.0.0.1: 50000
Added file: {_ id: ObjectId ('authorization'), filename: "mongodump.exe", chunkSize: 262144, uploadDate: new Date (1301404609850), md5: "647dcae88077e6
Fa2bb3be6b0cdebb07 ", length: 3271680}
Done!
Insert a file to the database wlb, that is, Mongodb/bin/mongodump.exe. The routing node of the Mongodb cluster used is 127.0.0.1, port is 50000, put is the command, it indicates uploading files to Mongodb, and there are also get and delete commands, which indicate obtaining and deleting files respectively.
Run the following command to start mongo, enter the wlb database, and run db. fs. files. find () to view the file list in GridFS.
D:/mongodb-win32-i386-1.8.0/cmd> cd d:/mongodb-win32-i386-1.8.0/bin
D:/mongodb-win32-i386-1.8.0/bin> call cmd.exe 127.0.0.1: 50000/admin
MongoDB shell version: 1.8.0
Connecting to: 127.0.0.1: 50000/admin
> Use wlb
Switched to db wlb
> Db. fs. files. find ()
{"_ Id": ObjectId ("4d91dbc1fb02c495a0a479d7"), "filename": "mongodump.exe", "chunkSize": 262144, "uploadDate": ISODate ("2011-03-29T13: 16: 49.850Z ")," md5 ":
"647dcae88077e6fa2bb3be6b0cdebb07", "length": 3271680}
2. Access files using Java APIs
Here the mongo-2.5.jar as an example, the code is as follows: