References:

https://www.cnblogs.com/lgh344902118/p/8656266.html

https://www.cnblogs.com/xuliuzai/p/10055535.htmlMongoDB official documentationhttps://docs.mongodb.com
https://docs.mongodb.com/manual/reference/operator/aggregation/
Copy the code

Lookup Federated query


user_faceswap_col = mydb["user_faceswap_col"A result = user_faceswap_col.aggregate([{'$lookup':
                {
                    "from": "all_faceswap_col", # another table B that needs to be syndicated"localField": "face_id"Select * from table A"foreignField": "face_id"Select * from table B"as": "face_docs"},}, {'$project'What fields should be displayed after the joint query?0: do not display {'face_docs._id': 0.'_id': 0,}}, {'$match': {
                            'user_id': '1001'}, # based on what criteria}, {'$sort': {"create_time": 1} # in ascending order of added time}])Copy the code