![](/img/trans.png)
[英]mongomock aggregate $lookup does not resolve collection name like real mongo db (python)
[英]Testing $lookup aggregations with Mongomock
我在其中有一个带有$lookup
的聚合查询:
pipeline = [{
'$match': {
'_id': ObjectId(layout_id)
}
}, {
'$lookup': {
'from': 'units',
'localField': 'unit_id',
'foreignField': '_id',
'as': 'layout_unit'
}
}, {
'$replaceRoot': {
'newRoot': {
'$mergeObjects': [{
'$arrayElemAt': ["$layout_unit", 0]
}]
}
}
}, {
'$project': {
'layout_unit': 0
}
}, {
'$lookup': {
'from': 'users',
'localField': 'user_id',
'foreignField': '_id',
'as': 'unit_user'
}
}, {
'$unwind': '$unit_user'
}]
我想用mongomock
进行单元测试。 这里的问题是,从版本3.9.0开始,它不支持$lookup
聚合。
NotImplementedError: Although '$lookup' is a valid operator for the aggregation pipeline, it is currently not implemented in Mongomock.
这有解决方法吗? 或者也许是mongomock
的替代解决方案?
可能已经晚了几个月,但由于我的计算机中的旧版本,我发现现在lib发布了该运营商的实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.