Created
July 29, 2019 14:12
-
-
Save jplsightm/68cbb77de63dfb7d3274e51258e13eec to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import pymongo | |
# get mongo sslog ids and ORDERIDS | |
ORDERIDs = {log['_id']: log['data']['fieldvalues']['ORDERID']['value'] | |
for log in sslog.find({'data.fieldvalues.ORDERID.value': {'$exists': True}}, {'data.fieldvalues.ORDERID.value': 1})} | |
# do some parsing because there was all sorts of badness - floats cast as strings, integers, etc | |
def order_id_to_string(_id, orderid): | |
try: | |
orderid = str(int(float(orderid))) | |
except ValueError: | |
pass | |
return _id, orderid | |
# run that function against the result set from my mongo query | |
type_corrected_orderids = [order_id_to_string(k,v) for k, v in ORDERIDs.items()] | |
# Update the sslogs | |
for k,v in type_corrected_orderids: | |
sslog.update_one({'_id': k}, | |
{'$set': {'data.fieldvalues.ORDERID.value': v}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment