koop-provider-mongodb v1.0.0
koop-provider-mongodb
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.
Required:
Install
To install/use this provider you first need a working installation of Koop. For information on using Koop, see https://github.com/esri/koop.
Getting started
- 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
process.on('SIGINT', () => process.exit(0)) process.on('SIGTERM', () => process.exit(0)) const Koop = require('koop') const koop = new Koop() const config = require('config') const provider = require('./index.js') koop.register(provider) const PORT = 8080 koop.server.listen(PORT);
Create configuration:
$ mkdir config $ cd config $ touch default.json
1. Fill default.json with proper data
```js
{
"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
Usage
By default, Koop will start listening on http://localhost:8080.
You can issue a request by using:
$ curl http://localhost:8080/mongodb/:id/FeatureServer0/query
Any query-parameters added to the request URL can accessed within getData and leveraged for data fetching purposes.
Example
If you need to check some example, you can visit the repository
Resources
6 years ago