0
私は9に経験3を持っており、給与の彼らの合計は、以下のデータ
から200000以下でなければなりません< = 4人の従業員を選択する必要が
{
"_id" : ObjectId("593a311650692f17327f9db3"),
"name" : "Anderson Heidenreich",
"experience" : 6,
"expected_salary" : 36252
}
{
"_id" : ObjectId("593a311650692f17327f9db4"),
"name" : "Dr. Collin Stanton IV",
"experience" : 8,
"expected_salary" : 56000
}
{
"_id" : ObjectId("593a311650692f17327f9db5"),
"name" : "Zita Von",
"experience" : 2,
"expected_salary" : 41792
}
{
"_id" : ObjectId("593a311650692f17327f9db6"),
"name" : "Gregory Reilly",
"experience" : 7,
"expected_salary" : 77000
}
{
"_id" : ObjectId("593a311650692f17327f9db7"),
"name" : "Prof. Myles Hackett",
"experience" : 3,
"expected_salary" : 49133
}
{
"_id" : ObjectId("593a311650692f17327f9db8"),
"name" : "Janelle Thiel",
"experience" : 4,
"expected_salary" : 78795
}
{
"_id" : ObjectId("593a311650692f17327f9db9"),
"name" : "Dr. Elsie Lang",
"experience" : 2,
"expected_salary" : 99135
}
{
"_id" : ObjectId("593a311650692f17327f9dba"),
"name" : "Sean Braun",
"experience" : 2,
"expected_salary" : 63608
}
{
"_id" : ObjectId("593a311650692f17327f9dbb"),
"name" : "Murray Simonis",
"experience" : 7,
"expected_salary" : 66000
}
よう
予想される出力
{
"_id" : ObjectId("593a311650692f17327f9db4"),
"name" : "Dr. Collin Stanton IV",
"experience" : 8,
"expected_salary" : 56000
}
{
"_id" : ObjectId("593a311650692f17327f9db6"),
"name" : "Gregory Reilly",
"experience" : 7,
"expected_salary" : 7700
}
{
"_id" : ObjectId("593a311650692f17327f9dbb"),
"name" : "Murray Simonis",
"experience" : 7,
"expected_salary" : 66000
}
mongodbクエリの操作方法を教えてください。
はありがとう
質問は200K未満に 'expected_salary'の*合計*を要求します。私は、レコードの制限で、あなたは4つのレコードを取得し、合計要件が満たされるまで1つをポップすることによってそれを行うことができると思います。 –
一般的には、https://docs.mongodb.com/manual/reference/operator/aggregation/group/を求めていますが、集計で条件文を実行することはできません。だから私は、問題の最初の部分についてKevinのアイデアを固執し、合計のアスペクトに対する結果処理の提案と解決策をとっています。 –
私の 'expected_salary'クエリの代わりに' .sort({"expected_salary":-1})。limit(4) '結果を受け取り、アプリケーション側でまとめて取得するだけです最終的な結果。 –