【发布时间】:2020-08-27 12:55:41
【问题描述】:
我在 Python 中有这个 MongoDB 查询。
results = collection.aggregate([
{
"$match": {
"monitor": {
"$in": [/\/tcp/,/\/http$/,/\/https_443$/,/\/https$/,/\/http_head_f5$/,/\/https_head_f5$/,/\/icmp$/]
}
}
},
{
"$project": {
"_id": 0,
"name": 1,
"partition": 1,
"fullPath": 1,
"type": 1,
"loadBalancingMode": 1,
"monitor": 1,
"f5ip": 1,
"poolstatus": 1
}}
])
我很难将此行转换为有效的 Python 语法
"$in": [/\/tcp/,/\/http$/,/\/https_443$/,/\/https$/,/\/http_head_f5$/,/\/https_head_f5$/,/\/icmp$/]
我尝试了“$regex”选项,但我们不能在 $in 中使用 $regex。 我还尝试将数组元素转换为字符串并转义斜杠,如下所示。
"$in": ["\/\/tcp\/","\/\/http$/"]
我想知道如何将 MongoDB 查询转换为有效的 python 语法并使用 PyMongo 接收相同的结果。
【问题讨论】:
-
这能回答你的问题吗? Performing regex Queries with pymongo
-
谢谢,它没有帮助,但它为我指明了正确的方向。见下文。