les*_*z3k 5 python unit-testing mongodb 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'
}]
Run Code Online (Sandbox Code Playgroud)
我想使用mongomock. 这里的问题是,从 3.9.0 版本开始,它不支持$lookup聚合。
NotImplementedError: Although '$lookup' is a valid operator for the aggregation pipeline, it is currently not implemented in Mongomock.
有解决方法吗?或者也许是替代解决方案mongomock?