简体   繁体   English

MySQL Document Store-创建索引时参数的值无效

[英]MySQL Document Store - Invalid value for argument when creating index

The \\help createIndex and Official Docs are different. \\help createIndexOfficial Docs不同。

I tried following the "shell manual" as it got me the farthest but I am still getting: 我尝试遵循“ shell手册”,因为它使我走得最远,但仍然得到:

db.col.createIndex("name", {"fields": [{"field": "name", "type": "TEXT"}, {"field": "name2", "type": "TEXT"}]})
Invalid value for argument 'fields[0].field' (MySQL Error 5017)

My collection has both name and name2, and I believe this has nothing to do with it. 我的收藏集同时包含name和name2,我认为这与它无关。

db.col.find()
[
    {
        "_id": "00005bcdb19f0000000000000001",
        "a": [
            1,
            2
        ],
        "name": "chen",
        "name2": "chen"
    }
]
1 document in set (0.0034 sec)

Any help would be appreciated 任何帮助,将不胜感激

It turns out that "field" in "fields" requires a JSONPath. 事实证明,“字段”中的“字段”需要JSONPath。 Also, TEXT will require some length. 另外,TEXT将需要一些长度。

The official documentation on this is severely lacking and even has some glaring errors. 有关此的官方文档严重缺乏,甚至有一些明显的错误。 I only figured this out in the course of trying to do the NoSQL equivalent of ALTER TABLE ADD UNIQUE INDEX some_index (field_one, field_two); 我只是在尝试做与NoSQL等效的ALTER TABLE ADD UNIQUE INDEX some_index (field_one, field_two); which seems to be unsupported. 似乎不受支持。

Anyways, try this: 无论如何,请尝试以下操作:

db.col.createIndex(
    "name", {
        "fields": [
            {"field": "$.name", "type": "TEXT(64)"},
            {"field": "$.name2", "type": "TEXT(64)"}
        ]
    }
)

EDIT regarding unique indexes: If you add a regular index to the collection and then go into workbench and drop the index you just created and re-add it as a unique index, that appears to work. 编辑有关唯一索引的信息:如果将常规索引添加到集合中,然后进入工作台并删除刚创建的索引,然后将其重新添加为唯一索引,则似乎可以正常工作。 But that's just for a single field. 但这只是一个领域。

EDIT regarding compund unique indexes: If you create a generated column that concatenates the two fields you want to be unique together and then apply a unique index on it, that will work. 有关完全唯一索引的编辑:如果创建一个生成的列,将希望唯一的两个字段连接在一起,然后在其上应用唯一索引,那将起作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用WHERE OR时的MySQL无效参数 - MySQL invalid argument when using WHERE OR Drupal 6将数组存储在mysql表中,因为varchar是错误提供的无效参数 - Drupal 6 store array in mysql table as varchar is error invalid argument supplied 尝试使用 MySQL Workbench 将 SQL Server 迁移到 MySQL。 错误:迁移数据时“[Microsoft][ODBC 驱动程序管理器] 无效的参数值” - Trying to migrate SQL Server to MySQL using MySQL Workbench. Error: “[Microsoft][ODBC Driver Manager] Invalid argument value” when migrating data Mysql无效的日期时间格式:1292创建一些虚拟数据进行测试时,日期时间值不正确 - Mysql Invalid datetime format: 1292 Incorrect datetime value when creating some dummy data for testing 为表 Mysql 创建索引时出错 - Error when creating Index for table Mysql 在MySQL中创建索引时索引名称的意义是什么? - What is the significance of the index name when creating an index in MySQL? 如何在 mysql 查询中存储索引的值而不是数组本身? - How to store the value of index not the array itself in mysql query? mysql:函数 json_extract 的参数 1 中的 JSON 文本无效:“值无效。” 在位置 0 - mysql: Invalid JSON text in argument 1 to function json_extract: "Invalid value." at position 0 mysql - 创建存储生成列时出现无效日期错误 - mysql - Invalid date error when creating stored generated column 在mysql表上创建索引 - Creating index on mysql table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM