O.Chounry
O.Chounry

Reputation: 322

How to create mongodb 2dsphere index on strapi?

My strapi project use Mongo database.

Strapi version : 3.0.0-beta.19.5

I have tried :

Is there any way to create a 2dspere index?

Upvotes: 0

Views: 548

Answers (1)

O.Chounry
O.Chounry

Reputation: 322

I just found a solution. I had to look up on the mongoose documentation index part.

In strapi documentation, they only tell that the value of 'index' is a boolean type. Which is different from mongoose doc. Actually the model.settings.json structure follow mongoose documentation.

So, to create the 2dsphere index we just need to specify "2dsphere" in the key "index" on that field.

Eg.

{
  "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>
    },
  }
}

<1> if true were specify, Single field index will be created on this field. But u can also specify other type of index, like in my case i use '2dsphere'.

UPDATE

What I said about

u can also specify other type of index

is not correct. The index type is limited because of the framework. So far I have test with 2dsphere, which is working. I test also text index, but it didn't work.

Upvotes: 3

Related Questions