【发布时间】:2019-04-10 01:43:46
【问题描述】:
在createIndex 的文档中,他们说db.collection.createIndex(keys, options),所以我用下面的代码调用createIndex()。我的数据库的名称是articles,集合的名称是bce。在bce 内部已经有一个包含article 字段的文档。
class Stockage():
def __init__(self):
self.connexion()
def connexion(self):
client = pymongo.MongoClient("localhost", 27017)
self.bce = client.articles.bce
sql = Stockage()
sql.bce.createIndex({article : "text"})
我有以下错误:
Traceback (most recent call last):
File "<ipython-input-1132-fc8762d315d1>", line 1, in <module>
sql.bce.createIndex({article : "text"})
File "C:\ProgramData\Anaconda3\lib\site-packages\pymongo\collection.py", line 3321, in __call__
self.__name.split(".")[-1])
TypeError: 'Collection' object is not callable. If you meant to call the 'createIndex' method on a 'Collection' object it is failing because no such method exists.
bce 不是一个集合吗?
【问题讨论】:
标签: python-3.x mongodb collections