1

我有一堵墙和几条与墙相关的评论,

{
    "Wall_id": "wall002",
    "user_id": "user002",
    "message_author": "AuthorB",
    "wall_message": "content:TRY",
    "posted_on": "24/8/15",
    "author_id": "A002",
    "path_to_files": ["home/path"],
    "wall_recepients":["user002","user003","user004","user005","user006"],
    "w_timestamp": 678,
    "Comments": [
        {
            "comment_id": "cmt001",
            "Wall_id": "wall001",
            "user_id": "user001",
            "pathtofile": "[home/doc/file]",
            "comment": "try 2",
            "profile_pic": "home2/pic.jpg",
            "user_name": "user2",
            "c_timestamp": 700
       },
        {
            "comment_id": "cmt001",
            "Wall_id": "wall001",
            "user_id": "user001",
            "pathtofile": "[home/doc/file]",
            "comment": "try 2",
            "profile_pic": "home2/pic.jpg",
            "user_name": "user2",
            "c_timestamp": 1000
       }
    ]
}

我想要一个查询,该查询对基于 w_timestamp 排序的墙元素和基于 c_timestamp 排序的每个墙的注释数​​组进行排序。

我正在使用 pymongo 并尝试过,

searchUser = "user002"
result = post.find({"wall_recepients":{"$in":[searchUser]}}).sort([["post.w_timestamp",DESCENDING],["post.Comments.c_timestamp",DESCENDING]])

DESCENDING 是 pymongo.DESCENDING

提前致谢!预期输出:

给定一个用户 id,获取 wall_recepients 包含 user_id 的所有墙项目,例如,

[

{
    "Wall_id": "wall002",
    "user_id": "user002",
    "message_author": "AuthorB",
    "wall_message": "content:TRY",
    "posted_on": "24/8/15",
    "author_id": "A002",
    "path_to_files": ["home/path"],
    "wall_recepients":["user002","user003","user004","user005","user006"],
    "w_timestamp": 678,
    "Comments": [
        {
            "comment_id": "cmt001",
            "Wall_id": "wall001",
            "user_id": "user001",
            "pathtofile": "[home/doc/file]",
            "comment": "try 2",
            "profile_pic": "home2/pic.jpg",
            "user_name": "user2",
            "c_timestamp": 700
       },
        {
            "comment_id": "cmt001",
            "Wall_id": "wall001",
            "user_id": "user001",
            "pathtofile": "[home/doc/file]",
            "comment": "try 2",
            "profile_pic": "home2/pic.jpg",
            "user_name": "user2",
            "c_timestamp": 1000
       }
    ]
},

{
    "Wall_id": "wall001",
    "user_id": "user002",
    "message_author": "AuthorB",
    "wall_message": "content:TRY",
    "posted_on": "24/8/15",
    "author_id": "A002",
    "path_to_files": ["home/path"],
    "wall_recepients":["user002","user003","user004","user005","user006"],
    "w_timestamp": 666,
    "Comments": [
        {
            "comment_id": "cmt001",
            "Wall_id": "wall001",
            "user_id": "user001",
            "pathtofile": "[home/doc/file]",
            "comment": "try 2",
            "profile_pic": "home2/pic.jpg",
            "user_name": "user2",
            "c_timestamp": 124
       },
        {
            "comment_id": "cmt001",
            "Wall_id": "wall001",
            "user_id": "user001",
            "pathtofile": "[home/doc/file]",
            "comment": "try 2",
            "profile_pic": "home2/pic.jpg",
            "user_name": "user2",
            "c_timestamp": 246
       }
    ]
}


]
4

0 回答 0