【问题标题】:Pymongo text index formattingPymongo 文本索引格式
【发布时间】:2019-06-06 09:16:19
【问题描述】:

我正在尝试使用 pymongo

索引 text field
from pymongo import MongoClient
mongo_client = MongoClient('localhost', 27017)
db = mongo_client["db_name"]

对象如下所示:

{'_id': ObjectId('5cf7d2d58a662ef15600033f'),
 'id': '13055',
 'type': 'municipality',
 'name': 'Marseille',
 'postcode': '13000',
}

我正在尝试将字段 name 索引为 string 以便能够对其执行文本搜索,不幸的是,我多次尝试后均未成功:

db.collection.create_index([{"$name": "text"}])

产生错误:

TypeError: not enough arguments for format string

同样,命令

db.collection.create_index([{"name": "text"}])

产生同样的错误:

TypeError: not enough arguments for format string

我确定这是一个简单的格式错误

【问题讨论】:

    标签: python python-3.x mongodb pymongo


    【解决方案1】:

    找到了,需要的格式是:

    db.collection.create_index([("name": "text")])
    

    【讨论】:

      猜你喜欢
      • 2014-10-21
      • 1970-01-01
      • 2020-10-10
      • 2019-04-18
      • 2017-03-21
      • 2012-08-05
      • 1970-01-01
      • 2016-03-06
      • 2011-08-20
      相关资源
      最近更新 更多