我正在尝试编写一些代码,这些代码将采用"假定的"域名,并将根据RFC 1035对其进行验证.例如,它需要满足以下规则:
[a-z0-9\-]仅为(输入时将域小写)google--com.com)我搜索了各种Python模块(例如:tldextract),但无济于事.
如何验证域名是否符合RFC 1035?
我有一个包含如下文档的集合:
{
"_id" : ObjectId("55b377cb66b393427367c3e2"),
"comment" : "This is a comment",
"url_key" : "55b377cb66b393427367c3df", //This is an ObjectId from another record in a different collection
}
Run Code Online (Sandbox Code Playgroud)
我需要在此集合中找到包含注释和url_key重复值的记录。
我可以轻松地生成(使用汇总)相同,单个键(例如:注释)的重复记录,但是我不知道如何对多个关键字进行分组/汇总。
这是我当前的聚合管道:
db.comments.aggregate([ { $group: { _id: { comment: "$comment" }, uniqueIds: { $addToSet: "$_id" }, count: { $sum: 1 } } }, { $match: { count: { $gte: 2 } } }, { $sort: { count : -1} }, {$limit 10 } ]);
Run Code Online (Sandbox Code Playgroud) mongodb mongodb-query aggregation-framework mongodb-aggregation
我在PyMongo中使用$ lookup成功“加入”两个集合(这可行)。我遇到的问题是,当我加入的第二个集合返回所有记录时,它可能超出BSON文档的大小。
我想使用$ limit来限制“ match_docs”下允许加入的记录数,例如:每个obj_id的“ comments”中最多记录100条记录:
db.indicators.aggregate([
{
"$lookup": {
"from": "comments",
"localField": "_id",
"foreignField": "obj_id",
"as": "match_docs"
}
}
])
Run Code Online (Sandbox Code Playgroud)
我尝试了各种类型的$ limit,它似乎仅限制了整个结果的总数,而不仅限于联接。
我已经在 DAG(Bash 和 Docker 操作员)中成功创建了动态任务,但是我很难将这些动态创建的任务传递给 xcom_pull 以获取数据。
for i in range(0, max_tasks):
task_scp_queue = BashOperator(task_id="scp_queue_task_{}".format(i), bash_command="""python foo""", retries=3, dag=dag, pool="scp_queue_pool", queue="foo", provide_context=True, xcom_push=True) # Pull the manifest ID from the previous task via xcom'
task_process_queue = DockerOperator(task_id="process_task_{}".format(i), command="""python foo --queue-name={{ task_instance.xcom_pull(task_ids=scp_queue_task_{}) }}""".format(i), retries=3, dag=dag, pool="process_pool", api_version="auto", image="foo", queue="foo", execution_timeout=timedelta(minutes=5))
task_manifest = DockerOperator(api_version="auto", task_id="manifest_task_{}".format(i), image="foo", retries=3, dag=dag, command=""" python --manifestid={{ task_instance.xcom_pull(task_ids=scp_queue_task_{}) }}""".format(i), pool="manfiest_pool", queue="d_parser")
task_psql_queue.set_downstream(task_scp_queue)
task_process_queue.set_upstream(task_scp_queue)
task_manifest.set_upstream(task_process_queue)
Run Code Online (Sandbox Code Playgroud)
如您所见,我尝试在 Jinja 模板中仅使用 Python 格式字符串来传递 i 变量,但这不起作用。
我也试过使用“task.task_id”,并只用 task_id 创建一个新字符串,但这也不起作用。
编辑:
现在命令看起来像这样
command="""python foo …Run Code Online (Sandbox Code Playgroud)