我刚刚找到了解决方案。我不得不查看mongoose documentation 索引部分。
在strapi文档中,他们只告诉'index'的值是一个boolean类型。这与猫鼬文档不同。实际上 model.settings.json 结构遵循 mongoose 文档。
因此,要创建 2dsphere 索引,我们只需在该字段的键“index”中指定“2dsphere”即可。
例如。
{
"kind": "collectionType",
"connection": "default",
"collectionName": "phone_stores",
"info": {
"name": "phoneStore"
},
"options": {
"increments": true,
"timestamps": true
},
"attributes": {
"car": {
"type": "integer",
"required": true
},
"userStoreId": {
"type": "objectId"
},
"location": {
"type": "json",
"index": "2dsphere" // <------ <1>
},
}
}
如果指定为 true,则将在此字段上创建 Single field index。但是你也可以指定其他类型的index,比如我使用'2dsphere'。
更新
我所说的
你也可以指定其他类型的索引
不正确。由于框架,索引类型受到限制。到目前为止,我已经用2dsphere 进行了测试,它正在工作。我也测试了text 索引,但是没有用。