[英]MySQL Document Store - Invalid value for argument when creating index
The \\help createIndex
and Official Docs are different. \\help createIndex
和Official 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.