MBischof
New Creator

CaaS and Geospatial-Index

Jump to solution

Hello community,

has anybody experience in generating and using a geospatial-index inside of the CaaS and want to share?

 

Usecase:

We store the data (address, opening times, location, latitude, longitude,...) of our branch-offices inside the Caas and our mobile app consumes the data. Now there should be some kind of proximity search to get the next X offices around my current location. 

We expanded our data and stored a GeoJson-Object additionally, but now the big question is, how to generate the geospatial-index. Helpdesk says, basically the Rest-Api leverages MongoDB's geospatial support but we have currently no Idea, how to start generating the index.

Any ideas to that out there ?

 

Thanks in advance for any suggestion, 

 

Best regards,

Marco

0 Kudos
1 Solution

Accepted Solutions
NMc
Crownpeak employee
Crownpeak employee
In general an index in the Rest API can be created by following this documentation:

 

You can read how a geospatial index would look like here: https://docs.mongodb.com/manual/geospatial-queries/#geospatial-indexes
 
An example Request could look like this:
 
curl --location --request PUT 'https://${customer}-${stage}caas-api.e-spirit.cloud/${tenant-id}/${project-uuid}.preview.content/_indexes/my-geospatial-index' \
--header 'authorization: apikey="*****************"' \
--header 'Content-Type: application/json' \
--data-raw '{
    "keys": {
        "2dsphere": 1
    }
}'
 

Kind regards,

Nico

View solution in original post

3 Replies
NMc
Crownpeak employee
Crownpeak employee
In general an index in the Rest API can be created by following this documentation:

 

You can read how a geospatial index would look like here: https://docs.mongodb.com/manual/geospatial-queries/#geospatial-indexes
 
An example Request could look like this:
 
curl --location --request PUT 'https://${customer}-${stage}caas-api.e-spirit.cloud/${tenant-id}/${project-uuid}.preview.content/_indexes/my-geospatial-index' \
--header 'authorization: apikey="*****************"' \
--header 'Content-Type: application/json' \
--data-raw '{
    "keys": {
        "2dsphere": 1
    }
}'
 

Kind regards,

Nico

groth
Crownpeak employee

Hi @MBischof ,

did the answer from @NMc help? If not I might suggest a slightly different payload for the curl request:

curl --location --request PUT 'https://${customer}-${stage}caas-api.e-spirit.cloud/${tenant-id}/${project-uuid}.preview.content/_indexes/my-geospatial-index' \
--header 'authorization: apikey="*****************"' \
--header 'Content-Type: application/json' \
--data-raw '{
    "keys": {
        "<fieldname>": "2dsphere"
    }
}'

Based on these resources:

Would love to get some feedback if your issue could be solved.

Best regards, Chris

HI @NMc

thanks for your reply. Based on your suggestions we found a working solution for us.

The basic things like the data-structure (Geo-Json Object) were correct before, the missing thing was to use a PUT-Statement to create the index over the correct field. Once this was done, getting the correct data with a $near-Operator was easy...

So again thanks for you help and best regards,

Marco

0 Kudos