This provider accesses a collection of documents in MongoDB, which translate into GeoJSON and Geoserviceslater.
This is provider was created from the koop-provider-sample that demonstrates how to build a Koop Provider.
To install/use this provider you first need a working installation of Koop. For information on using Koop, see https://github.com/esri/koop.
- Create a directory:
$ cd ~/Desktop
$ mkdir my_project
$ cd my_project
- To execute in the project:
$ npm init -y
npm init -y: generate the package.json file with default options (without asking any questions)
- Create
server.js
and add content:
$ touch server.js
const config = require('config')
const Koop = require('koop');
const koop = new Koop(config);
const FeatureServer = require('koop-output-geoservices')
const Provider = require('koop-provider-mongodb')
koop.register(Provider);
koop.register(FeatureServer);
// In Local Development, be aware that port has to be greater than 1024 ( Unpriviledge port)
koop.server.listen(8080);
- Create configuration:
$ mkdir config
$ cd config
$ touch default.json
- Fill default.json with proper data
{
"mongodb": {
"url": MongoDB connection string,
"databasename": Database name,
"collectionname": Collection name,
"field_id": Request field (:id),
"latitude": Latitude field database,
"longitude":Longitude field database,
"projectObj":fields to return in the documents that match the query filter.
}
}
- Install dependencies:
You must install the same version of
koop
as theprovider
.
$ npm i koop@3.9.4
$ npm i koop-provider-mongodb
- Start
node server.js
- If you need to debug it
node --inspect-brk server.js
By default, Koop will start listening on http://localhost:8080.
You can issue a request by using:
$ curl http://localhost:8080/mongodb/:id/FeatureServer
Any query-parameters added to the request URL can accessed within getData and leveraged for data fetching purposes.
If you need to check some example, you can visit the repository