4

Openshift で Python + MongoDB + PyMongo を使用しています

import os
import gridfs
from django.http import HttpResponse
from pymongo.connection import Connection
from django.shortcuts import get_object_or_404, render_to_response
from django.http import HttpResponseRedirect, HttpResponse
from django.template import Context, RequestContext,loader

connection = Connection('mongodb://sbose78:XXXXXX@staff.mongohq.com:10068/BOSE')
db=connection['BOSE']
fs=gridfs.GridFS(db)

_id でファイルを照会すると、これが得られます。

>>> fs.exists({"_id":'504a36d93324f20944247af2'})
False

対応するファイル名でクエリを実行すると:

>>> fs.exists({"filename":'foo.txt'})

True

何がうまくいかない可能性がありますか?

ありがとう。

4

2 に答える 2

15

pymongo バージョン < 2.2 の場合、ObjectId をインポートする必要があります

from pymongo.objectid import ObjectId

バージョン 2.2 以降では、インポートは代わりに

from bson.objectid import ObjectId

次に、次のように gridfs にクエリを実行できます。

fs.exists(ObjectId('504a36d93324f20944247af2'))
于 2012-09-10T01:30:07.533 に答える
0
fs.exists({"_id":ObjectId('504a36d93324f20944247af2')})

使用する必要がありますObjectId

于 2012-09-09T13:49:35.850 に答える