PyMongo - 创建索引时“语言覆盖不支持:C ++”

时间:2018-04-28 00:00:27

标签: python mongodb pymongo

我的收藏集posts包含看起来像这样的帖子

{
    "_id": "5ae37fd270f3e72399988198",
    "moderator": {
        "flagged": false,
        "reviewed": true,
        "pending": false,
        "time": "2018-04-27 20:34:38.099000",
        "account": "samhamou"
    },
    "author": "cryptohazard",
    "permlink": "security-enhancements-for-steem-messenger",
    "title": "Security enhancements for Steem Messenger",
    "repository": {
        "owner": {
            "login": "kingswisdom"
        },
        "fork": false,
        "html_url": "https:\/\/github.com\/kingswisdom\/SteemMessenger",
        "full_name": "kingswisdom\/SteemMessenger",
        "name": "SteemMessenger",
        "id": 127418766
    }
}

我正在尝试使用以下代码在我的一个Python文件中创建集合的索引

posts = DB.posts
posts.drop_indexes()
posts.create_index([
    ("author", "text"),
    ("moderator.account", "text"),
    ("repository.full_name", "text")
])

但是这给了我以下错误:

pymongo.errors.OperationFailure: language override unsupported: C++

如何防止这种情况发生?我可以使用this question的答案中的代码创建索引:

> db.posts.createIndex({
    "moderator.account": "text",
    author: "text",
    "repository.full_name": "text"
}, {
    "language_override": "en"
});

但是我希望能够在我的Python脚本中执行此操作,而不必从MongoDB shell中执行此操作。我尝试在我的Python脚本中找到一种添加"language_override": "en"选项的方法,但在检查documentation for create_index时似乎无法做到这一点。

0 个答案:

没有答案