User:Jules/mongobasic: Difference between revisions

From XPUB & Lens-Based wiki
(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...")
 
No edit summary
Line 20: Line 20:
<span style="font-family:monospace;font-size:13px">db.ips.find({'coordinates.0':12}).pretty()</span><br />
<span style="font-family:monospace;font-size:13px">db.ips.find({'coordinates.0':12}).pretty()</span><br />
<small>''→ anything with longitude of 12''</small>
<small>''→ anything with longitude of 12''</small>
<span style="font-family:monospace;font-size:13px">db.ips.find({ 'coordinates.0': {$gte: 1, $lte:12},'coordinates.1': {$gte:1, $lte:3.1} }).pretty()</span><br />
<small>''→ anything with longitude greater than 1 and lower than 12, latitude greater than 1 and lower than 3.1''</small><br />
<small>''This is very useful because it enables to give a range...''</small>


==export jsons==
==export jsons==

Revision as of 18:27, 20 November 2015

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

db.ips.find({ 'coordinates.0': {$gte: 1, $lte:12},'coordinates.1': {$gte:1, $lte:3.1} }).pretty()
→ anything with longitude greater than 1 and lower than 12, latitude greater than 1 and lower than 3.1
This is very useful because it enables to give a range...

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