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 です

前もって感謝します!期待される出力:

user 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