【发布时间】:2021-10-18 05:27:25
【问题描述】:
如何在mongodb中创建文档和集合来进行python代码配置。获取mongodb调用的属性名、数据类型、函数?
mongodb 集合示例示例
db.attributes.insertMany([
{ attributes_names: "email", attributes_datype: "string", attributes_isNull="false", attributes_std_function = "email_valid" }
{ attributes_names: "address", attributes_datype: "string", attributes_isNull="false", attributes_std_function = "address_valid" }
]);
Python 脚本和函数
def email_valid(df):
df1 = df.withColumn(df.columns[0], regexp_replace(lower(df.columns[0]), "^a-zA-Z0-9@\._\-| ", ""))
extract_expr = expr(
"regexp_extract_all(emails, '(\\\w+([\\\.-]?\\\w+)*@\\[A-Za-z\-\.]+([\\\.-]?\\\w+)*(\\\.\\\w{2,3})+)', 0)")
df2 = df1.withColumn(df.columns[0], extract_expr) \
.select(df.columns[0])
return df2
如何获取python脚本中所有的mongodb值,并根据属性调用函数。
【问题讨论】:
标签: python json mongodb pymongo