我有这个rethinkDB查询,它基本上返回了" basicConstraints"以" CA开头的字段:FA"。
然而,在我的一些文件中," basicConstraints"字段不存在。
q = r.db('scanafi').table(active_table) \
.concat_map(lambda doc: doc["certificates"]\
.concat_map(lambda x: x["parsed_certificate"]["X509 extensions"])\
.filter(lambda x: x["basicConstraints"]
.match("^CA:FA"))) \
.run()
如何在查询中包含所有包含此缺少字段的文档?
答案 0 :(得分:0)
It seems that your x
doesn't have methods like a regular python dict (I'm not familiar with rethinkdb). You could just use a real function here, with a try/except clause:
def basic_constraints(x):
try:
return x["basicConstraints"]
except: # find out what the actual exception is and put that here
return True
q = r.db('scanafi').table(active_table) \
.concat_map(lambda doc: doc["certificates"]\
.concat_map(lambda x: x["parsed_certificate"]["X509 extensions"])\
.filter(basic_constraints)
.match("^CA:FA"))) \
.run()## Heading ##
答案 1 :(得分:0)
您可以撰写x.has_fields('basicConstraints').not().or_(x['basicConstraints'].match("^CA:FA"))
。