> db.test2.insert({string:"aa bb cc"});
WriteResult({ "nInserted" : 1 })
> db.test2.insert({string:"aa 88 99"});
WriteResult({ "nInserted" : 1 })
> db.test2.ensureIndex({'string':"text"});
Error after setting ensureIndex:
{
"ok" : 0,
"errmsg" : "Index: { v: 2, key: { _fts: \"text\", _ftsx: 1 }, name: \"string_text\", ns: \"test2.test2\", weights: { string: 1 }, default_language: \ "english\", language_override: \"language\", textIndexVersion: 3 } already exists with different options: { v: 2, key: { _fts: \"text\", _ftsx: 1 }, name: \"post_text_text\", ns: \"test2.test2\", weights: { post_text: 1 }, default_language: \"english\", language_override: \"language\", textIndexVersion: 3 }",
"code" : 85,
"codeName" : "IndexOptionsConflict"
}
First in
v3.4
Version this methodensureIndex()
The name has been changed. Today’s other name iscreateIndex()
.DocumentSecondly, the usage of this method is
db.col.ensureIndex({"title":1})
Follow behind
1
Or ..-1
On behalf of the sorting method, can also betext
Is a full-text index or a geographic location index2d
Or2dphere
. (according to the @Mongoing Chinese community’s answer, add a few words)Chinese document
English documentThe above meaning should be that you have already set it and the index already exists. Conflict.