mongodb を使用し、pymongo 経由でアクセスしています。約 1000 行のドメイン テーブルにアクセスするには、どの方法が適しているでしょうか。注: findCat はループで 10,000 回呼び出されますか?
ディクショナリにキャッシュ
def __init__(self):
self.categories_dict=Utils.todict(db.collection.find_all)
def findCat(self, key):
return self.categories_dict(key)
または ダイレクトクエリ
def findCat(key):
#return object for the key
return db.collection.find_one