मैं अपने mongodb
pymongo
का उपयोग कर से कनेक्ट कर रहा हूँ:यह निर्धारित करने के लिए कि कोई फ़ील्ड मौजूद है या नहीं?
client = MongoClient()
mongo = MongoClient('localhost', 27017)
mongo_db = mongo['test']
mongo_coll = mongo_db['test'] #Tweets database
मैं एक कर्सर है और हर रिकॉर्ड के माध्यम से पाशन कर रहा हूँ:
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
try/except
के लिए कारण है क्योंकि अगर ["entities"]["urls"]
मौजूद नहीं है, यह त्रुटियों से बाहर है।
मैं कैसे निर्धारित कर सकता हूं कि ["संस्थाएं"] ["यूआरएल"] मौजूद है या नहीं?
भी कृपया "फ़ील्ड" की मेरी शब्दावली को सही करें –