1

I tried to test GridFS and I cannot get past this: I've put a file into a local gridfs.

$ mongofiles list connected to: 127.0.0.1 IMGP2224.JPG 1125745 

in the code I have:

from pymongo import MongoClient import gridfs ... def index(): db = MongoClient('localhost', 27017).gridfs files = gridfs.GridFS(db) image = files.list() import pdb;pdb.set_trace() **pdb here gives empty []** return render_template("index.html", images=image) 

What am I doing wrong?

1 Answer 1

3

If you don't provide a database name when you use mongofiles it will use the default database (which is called test). If you don't specify a collection name, it will use fs.files and fs.chunks.

So in your Python code you need to use test as the database name, instead of gridfs and then it will find your default fs.files and fs.chunks collections.

Sign up to request clarification or add additional context in comments.

2 Comments

well still, I'm getting a list that's ok. in mongo shell in test db: db.fs.files.find() gives {"_id": ObjectId("5287b92d53aad8ef5062a08c", "filename" : "IMGP2224.JPG".......} but in python code: files.exists(filename="IMGP2224.JPG") True files.get("5287b92d53aad8ef5062a08c") NoFile: no file in gridfs collection
Don't do: files.get("5287b92d53aad8ef5062a08c"). Do: files.get(ObjectId("5287b92d53aad8ef5062a08c")). ObjectIds and strings are different from each other.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.