[DevHub] A Free REST API for Johns Hopkins University COVID-19 dataset

The blog post is here: https://www.mongodb.com/developer/article/johns-hopkins-university-covid-19-rest-api

The REST API documentation is here: REST API MongoDB COVID-19 Open Data

I’m just creating this topic so we have a space to discuss, share improvement ideas or you can let me know if you need help to use this REST API.

Cheers,
Maxime.

5 Likes

Hi,
Thank you for the forum and the blg for the covid 19 api.
I do have a question, I appreciate the variety to obtain data for covid-19, but I haven’t been able to retrieve the data for each US state-- the state totals- cases, deaths, etc.
When i modify the parameters and eliminate selecting a county. It only returns all counties. I’m not seeing the data for the state’s totals.

Am I missing something obvious with that?

Thank you,
Lee

1 Like

Hi @Laura_Logan,

Thanks for looking into this project and for this question :smiley: !

That’s correct. In the REST API, you just have access to all the documents but I didn’t provide an API which provides a way to aggregate the data together… Because there are so many different aggregations we could build :grimacing: !

The easiest way to get this result is actually to go back to the MongoDB cluster directly and run an Aggregation Pipeline there directly.

You can connect like this:

mongo "mongodb+srv://readonly:readonly@covid-19.hip2i.mongodb.net/covid19"

Then you can use this aggregation for example:

[
  {
    '$group': {
      '_id': '$state', 
      'cases': {
        '$sum': '$confirmed_daily'
      }, 
      'deaths': {
        '$sum': '$deaths_daily'
      }
    }
  }
]

Which gives me the expected result in the Mongo Shell:

MongoDB Enterprise covid-19-shard-0:PRIMARY> use covid19
switched to db covid19
MongoDB Enterprise covid-19-shard-0:PRIMARY> db.us_only.aggregate([
...   {
...     '$group': {
...       '_id': '$state', 
...       'cases': {
...         '$sum': '$confirmed_daily'
...       }, 
...       'deaths': {
...         '$sum': '$deaths_daily'
...       }
...     }
...   }
... ])
{ "_id" : "New Hampshire", "cases" : 89983, "deaths" : 1261 }
{ "_id" : "Wisconsin", "cases" : 648094, "deaths" : 7402 }
{ "_id" : "Minnesota", "cases" : 547101, "deaths" : 7056 }
{ "_id" : "New Jersey", "cases" : 963484, "deaths" : 25006 }
{ "_id" : "Mississippi", "cases" : 308111, "deaths" : 7122 }
{ "_id" : "Maryland", "cases" : 430351, "deaths" : 8493 }
{ "_id" : "North Carolina", "cases" : 938784, "deaths" : 12325 }
{ "_id" : "Vermont", "cases" : 21488, "deaths" : 237 }
{ "_id" : "Rhode Island", "cases" : 143251, "deaths" : 2642 }
{ "_id" : "Guam", "cases" : 7851, "deaths" : 136 }
{ "_id" : "Ohio", "cases" : 1045945, "deaths" : 18917 }
{ "_id" : "Northern Mariana Islands", "cases" : 160, "deaths" : 2 }
{ "_id" : "Georgia", "cases" : 1078379, "deaths" : 19600 }
{ "_id" : "Virgin Islands", "cases" : 3005, "deaths" : 26 }
{ "_id" : "Maine", "cases" : 55374, "deaths" : 757 }
{ "_id" : "Illinois", "cases" : 1288844, "deaths" : 23865 }
{ "_id" : "Kentucky", "cases" : 434922, "deaths" : 6285 }
{ "_id" : "Indiana", "cases" : 701971, "deaths" : 13187 }
{ "_id" : "Louisiana", "cases" : 450673, "deaths" : 10264 }
{ "_id" : "North Dakota", "cases" : 105215, "deaths" : 1505 }
Type "it" for more

I can package all this is one JS script US_states.js like this:

use covid19;
var cursor = db.us_only.aggregate([ { '$group': { '_id': '$state', 'cases': { '$sum': '$confirmed_daily' }, 'deaths': { '$sum': '$deaths_daily' } } } ]);

while (cursor.hasNext()) {
  printjson(cursor.next());
}

And I can execute it like this directly from a shell:

$ mongo --quiet "mongodb+srv://readonly:readonly@covid-19.hip2i.mongodb.net/covid19" < US_states.js 
switched to db covid19
{ "_id" : "Diamond Princess", "cases" : 49, "deaths" : 0 }
{ "_id" : "Idaho", "cases" : 184347, "deaths" : 2006 }
{ "_id" : "Nevada", "cases" : 309150, "deaths" : 5353 }
{ "_id" : "Texas", "cases" : 2840869, "deaths" : 49359 }
{ "_id" : "Wyoming", "cases" : 57127, "deaths" : 703 }
{ "_id" : "Nebraska", "cases" : 215074, "deaths" : 2226 }
{ "_id" : "South Dakota", "cases" : 120379, "deaths" : 1948 }
{ "_id" : "Missouri", "cases" : 590452, "deaths" : 8995 }
{ "_id" : "South Carolina", "cases" : 564931, "deaths" : 9304 }
{ "_id" : "District of Columbia", "cases" : 46209, "deaths" : 1088 }
{ "_id" : "Arkansas", "cases" : 332666, "deaths" : 5680 }
{ "_id" : "Virginia", "cases" : 640211, "deaths" : 10510 }
{ "_id" : "Utah", "cases" : 391177, "deaths" : 2161 }
{ "_id" : "Grand Princess", "cases" : 103, "deaths" : 3 }
{ "_id" : "Michigan", "cases" : 850583, "deaths" : 17694 }
{ "_id" : "Puerto Rico", "cases" : 117836, "deaths" : 2182 }
{ "_id" : "Louisiana", "cases" : 450673, "deaths" : 10264 }
{ "_id" : "Indiana", "cases" : 701971, "deaths" : 13187 }
{ "_id" : "Illinois", "cases" : 1288844, "deaths" : 23865 }
{ "_id" : "Kentucky", "cases" : 434922, "deaths" : 6285 }
{ "_id" : "Maine", "cases" : 55374, "deaths" : 757 }
{ "_id" : "North Dakota", "cases" : 105215, "deaths" : 1505 }
{ "_id" : "Georgia", "cases" : 1078379, "deaths" : 19600 }
{ "_id" : "Northern Mariana Islands", "cases" : 160, "deaths" : 2 }
{ "_id" : "Ohio", "cases" : 1045945, "deaths" : 18917 }
{ "_id" : "Virgin Islands", "cases" : 3005, "deaths" : 26 }
{ "_id" : "Guam", "cases" : 7851, "deaths" : 136 }
{ "_id" : "Rhode Island", "cases" : 143251, "deaths" : 2642 }
{ "_id" : "Vermont", "cases" : 21488, "deaths" : 237 }
{ "_id" : "North Carolina", "cases" : 938784, "deaths" : 12325 }
{ "_id" : "Maryland", "cases" : 430351, "deaths" : 8493 }
{ "_id" : "Mississippi", "cases" : 308111, "deaths" : 7122 }
{ "_id" : "New Jersey", "cases" : 963484, "deaths" : 25006 }
{ "_id" : "Minnesota", "cases" : 547101, "deaths" : 7056 }
{ "_id" : "Wisconsin", "cases" : 648094, "deaths" : 7402 }
{ "_id" : "New Hampshire", "cases" : 89983, "deaths" : 1261 }
{ "_id" : "Oklahoma", "cases" : 444228, "deaths" : 6697 }
{ "_id" : "Massachusetts", "cases" : 664943, "deaths" : 17427 }
{ "_id" : "New York", "cases" : 1973308, "deaths" : 51350 }
{ "_id" : "Washington", "cases" : 380338, "deaths" : 5357 }
{ "_id" : "Florida", "cases" : 2141686, "deaths" : 34164 }
{ "_id" : "Hawaii", "cases" : 32271, "deaths" : 473 }
{ "_id" : "Montana", "cases" : 106631, "deaths" : 1526 }
{ "_id" : "Colorado", "cases" : 483820, "deaths" : 6173 }
{ "_id" : "Pennsylvania", "cases" : 1090228, "deaths" : 25502 }
{ "_id" : "West Virginia", "cases" : 147203, "deaths" : 2756 }
{ "_id" : "Alabama", "cases" : 520780, "deaths" : 10728 }
{ "_id" : "California", "cases" : 3708716, "deaths" : 60717 }
{ "_id" : "Iowa", "cases" : 358395, "deaths" : 5857 }
{ "_id" : "Alaska", "cases" : 65536, "deaths" : 314 }
{ "_id" : "Arizona", "cases" : 851265, "deaths" : 17109 }
{ "_id" : "Oregon", "cases" : 172206, "deaths" : 2449 }
{ "_id" : "Delaware", "cases" : 99515, "deaths" : 1591 }
{ "_id" : "American Samoa", "cases" : 0, "deaths" : 0 }
{ "_id" : "Tennessee", "cases" : 827579, "deaths" : 12032 }
{ "_id" : "Connecticut", "cases" : 327298, "deaths" : 7984 }
{ "_id" : "Kansas", "cases" : 306886, "deaths" : 4900 }
{ "_id" : "New Mexico", "cases" : 194378, "deaths" : 3996 }

I also checked that the sum of all the cases and deaths for all the states above actually sum up to 31.421.359 cases and 564.402 deaths. Which looks accurate to me.

image

Does that help? Let me know if you need something else :-).

You can actually run any aggregation you want directly in the MongoDB Cluster and shape the result set you want.

Cheers,
Maxime.

1 Like

Hello
I created an android application using the A Free REST API for Johns Hopkins University COVID-19 dataset.
I’d like to publish on google play, is there any limit?

Thank you,
H.S.D.

1 Like

Hi @HotSpring_Donut,

Excellent news! I’m glad you liked it and chose it for your implementation.
There aren’t any limit at the moment and I hope it won’t generate so much cost that we have to put some. The only problem I have at the moment is that I have to migrate the API because MongoDB retired the 3rd party services and I have to migrate to the new HTTPS endpoits.

Nothing would really change in the REST API itself, but it’s changing the endpoint (URL) itself.
At the moment, I’m trying to decide how to do that without breaking everything for everybody, but I don’t have a good solution as I can’t reach to all the REST API consumers and notify them that they need to migrate to the new one. :confused:

At least, I can reach out to you now!

I think I’ll duplicate the API, so the new one would be already available. Instead of just replacing the old one by the new one by migrating my Realm App.

Cheers,
Maxime.

1 Like