で平均を取得するので、私は私が1,000,000.00より大きい口座残高をすべてのアカウントの平均口座残高を取得したいこの情報はMongoDBの
{ "_id" : ObjectId("574462ffbb61fc35622bd1f3"), "first_name" : "GEORGE", "last_name" : "SMITH", "accounts" : [ { "account_type" : "Checking", "account_balance" : 7510049.716676093, "currency" : "PESO" }, { "account_type" : "Investment", "account_balance" : 8978088.436168617, "currency" : "USD" }, { "account_type" : "401K", "account_balance" : 3536582.866462197, "currency" : "YEN" }, { "account_type" : "Checking", "account_balance" : 4390095.46173461, "currency" : "USD" } ] }
{ "_id" : ObjectId("574462ffbb61fc35622bd1f4"), "first_name" : "STEVEN", "last_name" : "SMITH", "accounts" : [ { "account_type" : "Investment", "account_balance" : 7606194.17605087, "currency" : "EURO" }, { "account_type" : "Investment", "account_balance" : 2099711.775821766, "currency" : "EURO" }, { "account_type" : "Investment", "account_balance" : 2961011.973269031, "currency" : "YUAN" }, { "account_type" : "Savings", "account_balance" : 5830306.873168334, "currency" : "USD" }, { "account_type" : "401K", "account_balance" : 1542091.8696738125, "currency" : "EURO" } ] }
{ "_id" : ObjectId("574462ffbb61fc35622bd1f5"), "first_name" : "BRIAN", "last_name" : "SMITH", "accounts" : [ { "account_type" : "401K", "account_balance" : 149839.10500178766, "currency" : "PESO" } ] }
{ "_id" : ObjectId("574462ffbb61fc35622bd1f6"), "first_name" : "EDWARD", "last_name" : "SMITH", "accounts" : [ { "account_type" : "401K", "account_balance" : 6577381.434625924, "currency" : "YEN" }, { "account_type" : "Checking", "account_balance" : 8998935.759297138, "currency" : "USD" }, { "account_type" : "Investment", "account_balance" : 588000.4045217587, "currency" : "YUAN" }, { "account_type" : "Savings", "account_balance" : 6743563.754405159, "currency" : "YUAN" }, { "account_type" : "401K", "account_balance" : 8580650.627761671, "currency" : "POUNDS STERLING" }, { "account_type" : "401K", "account_balance" : 7687815.685781645, "currency" : "YEN" }, { "account_type" : "Checking", "account_balance" : 9128407.633252997, "currency" : "EURO" } ] }
を持つこのコレクション名bankdataを、持っています。
私はこのクエリを作成しましたが、平均勘定残高の取得方法はわかりません。
db.bankdata.find({ accounts: { $elemMatch : { 'account_balance' : { $gt: 1000000 } } } }, { 'accounts.$' : 1, first_name: 1, last_name: 1})