So first up you will need to find a host that offers MongoDB hosting. There are a few out there. For this tutorial I will be using Mongolab. MongoLab offers a sandbox account with 500mb usage which is perfect for what you will be using it for. Also they have CORS enabled
Once you have signed up you will need to create a new database and choose a host. I will name mine Geolocation and host it on AWS, be sure to select the free sandbox account. Don’t add any user info for the moment. You should now see the below screen.
Now click the “boom” collection to view its dashboard. We will need to get the api key from it. Once inside click the “Open Api view”. inside there you should see the Resource url. We need that. It should look like this with your api key:
So below we have a Button that when pressed Get’s the Geoposition object from the W3C Geolocation API.
So now we have some data we want to store, let’s store this in our newly created Mongo Database.
Below we have a standard jQuery Ajax post. The url is set to your newly created database with your own Api key.The data being an object needs to be stringified prior to being posted.
Now when you run this on a server when clicking the button you will see the data being sent to mongolab in Chrome dev tools.
Note: you cannot run this locally
When you check your MongoLabs DB you will see your database full of awesome data. When you browse to your API url you will have a json object that you can now use.
Below is a complete code example: