user_data = collection.aggregate([{
'$match': {
"user_id": user_id
}
}, {
'$sort': {
'created_at': pymongo.DESCENDING
}
}, {
'$lookup': {
'from': 'artwork_images',
'localField': '_id',
'foreignField': 'artwork_id',
'as': "artwork_images"
}
}, {
'$lookup': {
'from': 'artwork_moods',
'localField': '_id',
'foreignField': 'artwork_id',
'as': "moods"
}
}, {
'$lookup': {
'from': 'artwork_mediums',
'localField': '_id',
'foreignField': 'artwork_id',
'as': "mediums"
}
}, {
'$lookup': {
'from':
'artwork_collaborators',
'localField':
'_id',
'foreignField':
'artwork_id',
'pipeline': [{
'$lookup': {
'from': "users",
'localField': "user_id",
'foreignField': "_id",
'as': "collaborator_info"
}
}],
'as':
"artwork_collaborator",
},
}, {
'$facet': {
'data': [{
'$skip': skip
}, {
'$limit': page_size
}],
'metadata': [{
'$count': 'total',
}],
}
}])
I am using pymongo to query, and i need to update above query so that, if i pass collection_id in match, then results will show that collection_id at top from that users artwork collection and then the rest of the collection with pagination