User:Jules/mongobasic

From XPUB & Lens-Based wiki
< User:Jules
Revision as of 19:06, 20 November 2015 by Jules (talk | contribs) (Created page with "==Import the Geoip database== I was lucky to find the MaxMind GeoIP2 legacy csv imported in MongoDB here:<br /> http://www.poeticoding.com/downloads/mongodb/mongodb_geoips.zip...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Import the Geoip database

I was lucky to find the MaxMind GeoIP2 legacy csv imported in MongoDB here:
http://www.poeticoding.com/downloads/mongodb/mongodb_geoips.zip
I unzipped the folder for the dump and used mongorestore to import it.

First steps

db.ips.find()
→ will find anything

db.ips.find().pretty()
→ for it to be readable

db.ips.find({'location.country_name' : /^antarctica$/i}).pretty()
→ Will find ips in antarctica and show them in a readable way (the ^ is here in case it's a lower or upper case first letter)

db.ips.find({'coordinates.1':12}).pretty()
→ anything with latitude of 12

db.ips.find({'coordinates.0':12}).pretty()
→ anything with longitude of 12

export jsons

mongoexport -d poetic_geoips -c ips -q "{'location.country_name' : /^antarctica$/i}" --jsonArray --out antarctica.json
→ get a json file of all the ips in Antarctica

mongoexport -d poetic_geoips -c ips -q "{'location.city_name' : /^rotterdam$/i}" --jsonArray --out rotterdam.json
→ to get a json file of all the ips in Rotterdam