从任何特定用户的数据中获取特定记录
user_artworks = artworks.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',
}],
}
}])
我有上面的查询要像这样更新,这样,如果我发送与 user_id 匹配的artwork_id,那么结果会显示artwork_id 位于顶部,然后所有条件(例如它们现在正在使用分页)工作
,或者
如果没有任何解决方案可以更新上面的查询与匹配然后有什么选项可以让我在顶部显示一些特定的artwork_id从搜索用户的艺术品收藏与分页(上面的查询可以帮助模式来理解问题)
user_artworks = artworks.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 have above query to update like this, so that if i send artwork_id in match with user_id, then the results show that artwork_id at top and then all the conditions like they are working right now with pagination
OR
If there is not any solution to update above query with match then is there any option that i can show some specific artwork_id at top from searched user's artwork collection with pagination(above query can help with schema to understand the problem)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论