mongodb 建立索引总是说没有createindex 方法

index = self.xiaoMiQuanCollection.createIndex({"unique_charcter": 1, "name": 'hashed'}, {"unique": True})
res = self.xiaoMiQuanCollection.find(index)

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.

我写ensureIndex 也不对,求指教### 题目描述

阅读 5.7k
2 个回答

self是什么类型?除非self继承了database否则不会直接取到collection。就算是,那语法也应该是: self["xiaoMiQuanCollection"].createIndex(...)

先看看文档学学基本操作:http://api.mongodb.com/python...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题