已解决16.17K 浏览2021/11/04其他 0 92136591528 2021/11/02 1条评论 关于使用aggregate进行联合查询时候,当子条件限制的id存在特殊的美元符号$的时候,mongo会认为这是一个列,而不是值的问题 921365915 选择最佳答案 2021/11/04 921365915 已评论 2021/11/03 比如下面这个例子在expr表达式,and里面第二个$eq,我想表达,我的列tenant_virtual_account等于这个id“$-v2131231asdadsad2sadaasdasdass3”,但是由于$是特殊字符,在程序中会被任务这是一个名为“-v2131231asdadsad2sadaasdasdass3”的列,这就与我所需要的不相符合了。 db.t_application_business.aggregate( [{ “$lookup”: { “from”: “t_user_application_business_role_permission”, “let”: { “main_business_id”: “$business_id” }, “pipeline”: [{ “$match”: { “$expr”: { “$and”: [{ “$eq”: [“$business_id”, “$$main_business_id”] }, { “$eq”: [“$tenant_virtual_account”, “$-v2131231asdadsad2sadaasdasdass3”] }, { “$eq”: [“$status”, 0] }, { “$eq”: [“$delete_flag”, 0] }] } } }, { “$project”: { “tenant_virtual_account”: 1, “role_id”: 1, “application_id”: 1, “create_time”: 1, “status”: 1 } }], “as”: “businessRolePermission” } }, { “$lookup”: { “from”: “t_business_role”, “localField”: “businessRolePermission.role_id”, “foreignField”: “role_id”, “as”: “applicationBusinessRole” } }, { “$match”: { “businessRolePermission”: { “$ne”: [] }, “application_id”: { “$in”: [“63299bd172f24fe18924598cd5695a1a”] }, “status”: 0, “delete_flag”: { “$in”: [0] } } }, { “$project”: { “business_name”: 1, “business_id”: 1, “businessRolePermission”: 1, “applicationBusinessRole”: 1, “create_time”: 1 } }, { “$sort”: { “businessRolePermission.create_time”: 1 } }, { “$skip”: 0 }, { “$limit”: 20 }] ) 3 答案 活跃已投票最新最老的 0 xiaoxu1.13K 发布 2021/11/04 0 条评论 好的,把问题更新为已解决 xiaoxu 已回答的问题 2021/11/04 您正在查看3个答案中的1个,单击此处查看所有答案。 注册 或 登录
比如下面这个例子在expr表达式,and里面第二个$eq,我想表达,我的列tenant_virtual_account等于这个id“$-v2131231asdadsad2sadaasdasdass3”,但是由于$是特殊字符,在程序中会被任务这是一个名为“-v2131231asdadsad2sadaasdasdass3”的列,这就与我所需要的不相符合了。
db.t_application_business.aggregate(
[{
“$lookup”: {
“from”: “t_user_application_business_role_permission”,
“let”: {
“main_business_id”: “$business_id”
},
“pipeline”: [{
“$match”: {
“$expr”: {
“$and”: [{
“$eq”: [“$business_id”, “$$main_business_id”]
}, {
“$eq”: [“$tenant_virtual_account”, “$-v2131231asdadsad2sadaasdasdass3”]
}, {
“$eq”: [“$status”, 0]
}, {
“$eq”: [“$delete_flag”, 0]
}]
}
}
}, {
“$project”: {
“tenant_virtual_account”: 1,
“role_id”: 1,
“application_id”: 1,
“create_time”: 1,
“status”: 1
}
}],
“as”: “businessRolePermission”
}
}, {
“$lookup”: {
“from”: “t_business_role”,
“localField”: “businessRolePermission.role_id”,
“foreignField”: “role_id”,
“as”: “applicationBusinessRole”
}
}, {
“$match”: {
“businessRolePermission”: {
“$ne”: []
},
“application_id”: {
“$in”: [“63299bd172f24fe18924598cd5695a1a”]
},
“status”: 0,
“delete_flag”: {
“$in”: [0]
}
}
}, {
“$project”: {
“business_name”: 1,
“business_id”: 1,
“businessRolePermission”: 1,
“applicationBusinessRole”: 1,
“create_time”: 1
}
}, {
“$sort”: {
“businessRolePermission.create_time”: 1
}
}, {
“$skip”: 0
}, {
“$limit”: 20
}]
)