[阅读: 263] 2010-02-27 02:36:45
原来是跟pymongo并行的,不是那个包下面的
import sys
from pymongo.connection import Connection
from pymongo.errors import ConnectionFailure
import gridfs
# Make a connection to Mongo.
try:
connection = Connection("localhost", 27017)
except ConnectionFailure:
print "couldn't connect: be sure that Mongo is running on localhost:27017"
sys.exit(1)
# We need a database for GridFS to use, but first make sure it's clean.
connection.drop_database("pymongo_examples")
db = connection["pymongo_examples"]
# Create our GridFS instance
fs = gridfs.GridFS(db)
# Open a GridFile for writing, and write some content
f = fs.open("hello.txt", "w")
f.write("hello ")
f.write("world")
f.close()
# Now print the contents of the file
g = fs.open("hello.txt")
print g.read()