0

私はこのコレクションを持っています:

{
        "_id" : ObjectId("522f05f06f92046814003b84"),
        "personal_id" : "0609150071",
        "superstructure_id" : 1,
        "name" : "David",
        "surname" : "Bar",
        "plays_often" : 1,
        ...
        "created" : ISODate("2013-09-10T13:43:38Z")
}
{
        "_id" : ObjectId("522f05f06f92046814003b84"),
        "personal_id" : "0609150071",
        "superstructure_id" : 1,
        "name" : "David",
        "surname" : "Bar",
        "plays_often" : 1,
        ...
        "created" : ISODate("2013-09-10T14:11:55Z")
}
...

次のレコードを検索する必要があります。

  • 基準:superstructure_id: 1

  • でグループ化personal_id

  • createdこれらのグループから、フィールドに基づいて最新のレコードのみを返します

  • 次に、すべてのグループ結果を並べ替えますplays_often

  • 制限付き 5

"personal_id" : "0609150071"そのため、新しい日時が にあるため、結果には次のレコードのみが含まれcreatedます:

{
        "_id" : ObjectId("522f05f06f92046814003b84"),
        "personal_id" : "0609150071",
        "superstructure_id" : 1,
        "name" : "David",
        "surname" : "Bar",
        "plays_often" : 1,
        ...
        "created" : ISODate("2013-09-10T14:11:55Z")
}

これはmongodbで可能ですか?

4

1 に答える 1