如何使用pymongo创建索引

马克西米利安

我想在我的Mongo数据库中的特定字段上启用文本搜索。我想在python(-> pymongo)中实现此搜索。当我按照互联网上的说明进行操作时:

db.foo.ensure_index(('field_i_want_to_index', 'text'), name="search_index")

我收到以下错误消息:

    Traceback (most recent call last):
    File "CVE_search.py", line 8, in <module>
    db.foo.ensure_index(('field_i_want_to_index', 'text'), name="search_index")
 File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 1599, in ensure_index
        return self.create_index(key_or_list, cache_for, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 1466, in create_index
        index_doc = helpers._index_document(keys)
      File "/usr/local/lib/python2.7/dist-packages/pymongo/helpers.py", line 100, in _index_document
            for (key, value) in index_list:
    ValueError: too many values to unpack

在pymongo中是否有其他/更好的方法来创建索引?

克列丹

使用将create_index键作为数组和TEXT索引方向传递方法

collection.create_index([('field_i_want_to_index', pymongo.TEXT)], name='search_index', default_language='english')

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章