Sto collegandomi al mio mongodb
utilizzando pymongo
:come determinare se esiste un campo?
client = MongoClient()
mongo = MongoClient('localhost', 27017)
mongo_db = mongo['test']
mongo_coll = mongo_db['test'] #Tweets database
Ho un cursore e sto scorrendo ogni record:
cursor = mongo_coll.find()
for record in cursor: #for all the tweets in the database
try:
msgurl = record["entities"]["urls"] #look for URLs in the tweets
except:
continue
Il motivo per il try/except
perché se ["entities"]["urls"]
non esiste, si sbaglia.
Come determinare se ["entità"] ["URL"] esiste?
anche si prega di correggere la mia terminologia di "campo" –