- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
在 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
不是一个集合吗?
最佳答案
这是因为在 Pymongo 中,该方法被称为 create_index()
而不是 createIndex()
,因为它在 mongo
shell 中被命名。
与对应的 mongo
shell 相比,它的参数格式也不同。它不接受文档/字典作为索引规范,而是接受元组列表。这是因为您无法保证 Python 中字典键的顺序。
所以正确的行应该是:
sql.bce.create_index([("article", pymongo.TEXT)])
有关更多详细信息,请参阅 Pymongo Collection页面。
关于python-3.x - 方法 createIndex() 不可在集合上调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53175729/
我有一个 QTableView 和 QAbtractTableModel 子级的相应实例。 我惊讶地发现,如果我的表模型实例发出命名单个单元格的 dataChanged,Qt 框架将向我的表模型的::
任何人都知道如何创建一个索引,其中术语是一个 ref 并且可以通过数组中的嵌套对象进行搜索? 在“对话”集合中,我保存了以下示例数据: { "created": Time("2019-09-29T
我正在尝试将 Liquibase 用于我们的项目。我们主要使用 Oracle 数据库,其他一些数据库较少使用。我试图弄清楚如何在索引的情况下指定列顺序。下面是一个典型的创建索引更改集。
createIndex = true不会使用spring-data-elasticsearch在Elasticsearch中创建索引映射 @Document(indexName = "profiles
回答这个问题:Postgres table constraint using group-by ,我正在尝试将以下 Postgres 代码翻译成 liquibase XML create unique
我正在尝试将 Elasticsearch for GO 与这个著名的 repo 结合使用 但是,当我尝试创建一个 index(docs,并作为示例给出 here)时: // Define an
所以我正在使用 TypeScript 构建一个 express 服务器,使用 mongoose 与 MongoDB Atlas 交互。最近我决定在我的应用程序中使用多个数据库并更改我的架构以适应这种新
我正在使用 Ionic 3、Angular 4、Pouchdb、Pouchdb-find Pouchdb 工作正常。 我已经通过 npm 安装了 pouchdb 和 pouchdb-find 重现步骤
为了这个问题的目的,我有两个业务类: @Entity @Indexed public class MyClassOne implements MyInterface { @Id pri
我正在为几千兆位的文档创建索引。 在我的 mongo shell 中,我运行了这个命令: db.positions.createIndex( { "imei": 1, "server_date": -
我有一个包含时间类型字段的集合。我需要能够按年或月-年组合查询此集合。 我曾尝试在网站本身上使用索引创建工具,例如 Year(data.expDate)和 Month(data.expDate)在条款
当子类化 QAbstractTableModel 时,获取给定行和列的 QModelIndex 的正确方法是什么(例如,提供便捷方法 data(int row, int column))? 有inde
我正在尝试创建一个代理模型来动态映射来自源模型的项目。 在 QIdentityProxyModel 的实现之后,我发现实际上不可能通过检查 4 个核心函数来复制它: mapFromSource() m
我只是想创建一个像这样的基本索引 currentDB.createIndex({ index: { fields: ['name'] } }).then((result
所以我尝试在我的 messageSchema 中创建索引 var messageSchema = new Schema({ senderName : String, conte
在 createIndex 的文档中,他们说 db.collection.createIndex(keys, options) 所以我调用 createIndex()下面的代码。我的数据库名称是 ar
我一直在阅读 MDN,但我得到了 stuff like : keyPath The key path for the index to use. Note that it is possible to
我想为一个mongodb集合创建主键,看教程时,下面的东西总是没有解释。 mongodb的“createIndex”参数值是什么意思? 例如,在 https://www.sitepoint.com/7
是否可以使用 EF Code First 迁移的 CreateIndex 语法来创建覆盖索引(*请参阅下文了解覆盖索引是什么)。 例如,我可以像这样在手动迁移中创建一个简单的索引: CreateInd
在我的购物车 Controller 中,我有以下代码段: const Cart = require('mongoose').model('Cart'); 这有效: cart = await Cart.
我是一名优秀的程序员,十分优秀!