5

I got an aggregation query with $lookup inside it:

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'
}]

I would like to unit-test it using mongomock. The issue here is, that as of version 3.9.0 it doesn't support $lookup aggregations.

NotImplementedError: Although '$lookup' is a valid operator for the aggregation pipeline, it is currently not implemented in Mongomock.

Is there a workaround to this? Or perhaps a substitute solution to mongomock?

lesz3k
  • 148
  • 9

1 Answers1

0

Maybe a few months late but because of old version in my computer I discovered that now the lib released an implementation for that operator.

Pull request

Nadav
  • 574
  • 10
  • 24
  • Still seeing the same error although It is implemented. Can you share the code or version if you've solved this issue in your code? – Amulya K Murthy Feb 17 '20 at 11:17