2011-12-29 python mongodb gridfs
Пример использования GridFS (mongodb) в Python
from pymongo import Connection
import gridfs
# Подключение к GridFS
db = Connection().test
fs = gridfs.GridFS(db)
# Запись, чтение
file_id = fs.put('hello world')
print fs.get(file_id).read()
# Записать объект-файл
file_id = fs.put(open('img.jpg'), content_type="image/jpeg", filename="image.jpg")
print fs.get(file_id).content_type
# Получить последнюю версию по имени файла
file_id = fs.put('hello 1', filename = 'test_history')
file_id = fs.put('hello 2', filename = 'test_history')
print fs.get_last_version('test_history').read()
fs.delete(file_id)
print fs.get_last_version('test_history').read()