Skip to content
Jonah Duckles edited this page Feb 28, 2012 · 1 revision

Mongo Interface

This api provides read-only access to data stored in the cyberCommons MongoDB

Methods

/mongo/db_find

  • db - database
  • col - collection
  • query - Mongo query (optional)
  • callback - Callback for JSONP (optional)
  • showids - Boolean for returning internal Mongo _id's (defaults to False)

All arguments can be provided as GET or POST arguments and/or positional arguments in the order above.

Example:

http://test.cybercommons.org/mongo/db_find/?db=flora&col=data

is the same as:

http://test.cybercommons.org/mongo/db_find/flora/data/

which is the same as:

wget --post-data "db=flora&col=data" http://test.cybercommons.org/mongo/db_find/ -O flora.json
Examples

List databases:

http://test.cybercommons.org/mongo/db_find/

List collections:

http://test.cybercommons.org/mongo/db_find/flora/

Query a collection any kwarg for pymongo's collection.find() will be passed:

http://test.cybercommons.org/mongo/db_find/flora/data/{'spec':{'REF_NO':11}}
http://test.cybercommons.org/mongo/db_find/flora/data/{'limit': 10}
http://test.cybercommons.org/mongo/db_find/flora/data/{'spec':{'REF_NO':11},'fields':["REF_NO","NO_Genera","NO_Species"]}
http://test.cybercommons.org/mongo/db_find/flora/data/{'spec':{'REF_NO':11}}

Query with callback:

http://test.cybercommons.org/mongo/db_find/flora/data/?callback=Somefunction
http://test.cybercommons.org/mongo/db_find/flora/data/{'spec':{'REF_NO':11},'fields':["REF_NO","NO_Genera","NO_Species"]}?callback=Anotherfunction

/mongo/distinct

  • db - database
  • col - collection
  • distinct_key - key to compute distinct over
  • query - query to limit data
  • callback (optional)

Examples:

http://test.cybercommons.org/mongo/distinct/teco/taskresults/year/{'spec':{'task_id':'961d4f18-d88e-4cbd-8849-42a9a712ff82'}}

/mongo/group_by

  • db - database
  • col - collection
  • key - key to aggregate over
  • variable - variable to sum, count and average
  • callback - Callback for JSONP (optional)

Example:

http://test.cybercommons.org/mongo/group_by/teco/taskresults/['year','month']/npp/{'task_id':'20b9a88d-fe01-4f7b-9920-19b1dac68632'}

/mongo/find_loc

Returns a GeoJSON object for each Mongo object containing latitude and longitude keys

Clone this wiki locally