[英]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.