0

There is option of GridFS but that requires a driver(some language). Can't we insert a file in a table and display as a field(may b the path of file)? I tried one approach using Gridfs in python.

from pymongo import MongoClient

import gridfs

db = MongoClient().gridfs_example

fs = gridfs.GridFS(db)

a = fs.put("hello world")

After using the last command in pymongo, a error is coming..

Aman Kaushik
  • 83
  • 2
  • 8
  • Google to the rescue: http://docs.mongodb.org/manual/reference/program/mongofiles/ – Sammaye Jul 29 '14 at 13:20
  • Can u share the code for storing a file (say c:\img.png) ? – Aman Kaushik Jul 29 '14 at 14:09
  • 1
    `mongofiles -d test put C:\img.png` – Sammaye Jul 29 '14 at 14:15
  • thanks it works.. but i had to start mongofiles.exe from cmd . it didnt work in mongo.exe terminal – Aman Kaushik Jul 29 '14 at 14:35
  • Indeed, it is a separate program, helper effectively, that comes bundled with MongoDB itself as such it is like mongodump or one of the other programs you run. Yes, since your on Windows it is .exe not just mongofiles. – Sammaye Jul 29 '14 at 14:37
  • Thanks a lot Sammaye. One last thing. Can u tell me how to store the address/reference of the file in a collection. Say my collection has 3 fields ... heading, image_address,description.. It would be very helpful. Thanks in advance.. – Aman Kaushik Jul 29 '14 at 14:48
  • there will be a fs.files collection, within that there will be a file_id, you can take this file id and save it to a record witin one of your collections, from there you can then reference the file around your app – Sammaye Jul 29 '14 at 15:17

2 Answers2

0

You can keep the path of the file stored on server in collection that is being used. As there is only 16 MB limitation to store in collection for a field.

so you can store the filename/path in collection.

Please correct me if i am wrong.

kamal
  • 996
  • 15
  • 25
0
  1. there are no "tables" in mongodb
  2. nope there is the GridFS extension to store files in the database

You could upload the image files in a folder or objectid dependend folders and store the paths in your collection.