Created
April 23, 2017 12:54
-
-
Save senaps/c741a49d4860fbada14fd1c559cb4341 to your computer and use it in GitHub Desktop.
simple code to edit geo location and add a simple field to 20000 mongodb documents!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print " starting the thing!" | |
import time | |
from pymongo import MongoClient | |
client = MongoClient('localhost',27017) | |
db = client['Pakar'] | |
collection = db.person | |
print "db and collection were selected!" | |
time.sleep(2) | |
print "starting to fix is_set field!" | |
sent_fix = 0 | |
sent_fail = 0 | |
for man in collection.find(): | |
try: | |
collection.update({"code_meli": man.get('code_meli')}, {'$set':{"is_sent": 0}}) | |
sent_fix += 1 | |
except: | |
sent_fail += 1 | |
print "collections were updated with is_set" | |
print "we had %i's with %i's failing to edit!" % (sent_fix, sent_fail) | |
time.sleep(3) | |
print "starting to edit locations!" | |
location_fix = 0 | |
location_fail = 0 | |
for man in collection.find(): | |
try: | |
lat_fixed = map(float, man['lat'].split(',')) | |
lat = {"loc": lat_fixed} | |
collection.update({"code_meli" : man.get('code_meli')}, {'$set': {"lat": lat}}) | |
location_fix += 1 | |
except: | |
#print man['_id'] | |
location_fail += 1 | |
print "turning location is done too!" | |
print "we had %i okay and %i 's failed!" %(location_fix, location_fail) | |
time.sleep(3) | |
print "bye senaps!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment