从任何特定用户的数据中获取特定记录

发布于 2025-01-21 01:40:27 字数 1480 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文