我连接我的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"]
不存在,它错误了。
我怎么能确定[ “实体”] [ “网址”]是否存在?
也请更正我的术语“字段” –