Search code examples
geojsonloopbackjs

Best way to store geojson data using loopback for rest api


New to loopback but having fun setting up my first node based RestAPI. I am able to create models and have the associated tables created in the datastore. My models need to have properties which are data type geojson, a string of the form:

{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [125.6, 10.1] } }

Some are points. Others polylines or polygons. My question is, what is the best way to configure geojson properties in the model schema. I could just set the data type to string I guess but I am hoping there is something more elegant. Ideally I would like to setup custom validation that will check that submitted data is valid geojson. Also I need to be able to query the models by location, e.g. return data within lat/lng bounds.

I choose MYSQL as the datastore for now but only because of past experience. If another data source would be preferable I'll change.


Solution

  • I see Raymond answered this question on the mailing list too.

    1. For NoSQL DB such as mongodb, you can store the object directly as subdocument.
    2. For relational databases such as MySQL, you can define the property type as Object. LoopBack will store them as TEXT/CLOB.
    3. If the DB has native types for geo related data, we can potentially enhance the type mapping for connectors to take advantage of them.

    https://groups.google.com/forum/#!topic/loopbackjs/D0WCPIfHhR8