mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-11 09:55:13 +08:00
updated aggregate function
This commit is contained in:
parent
eccbcfb615
commit
f03f7ba9d2
1 changed files with 8 additions and 47 deletions
|
|
@ -19,68 +19,29 @@ class LeaderboardsDAO {
|
|||
}
|
||||
|
||||
static async update(mode, mode2, language, uid = undefined) {
|
||||
let str = `personalBests.${mode}.${mode2}`;
|
||||
let str = `lbPersonalBests.${mode}.${mode2}.${language}`;
|
||||
let lb = await mongoDB()
|
||||
.collection("users")
|
||||
.aggregate([
|
||||
{
|
||||
$unset: [
|
||||
"_id",
|
||||
"addedAt",
|
||||
"email",
|
||||
"oldTypingStats",
|
||||
"tags",
|
||||
"bananas",
|
||||
"discordId",
|
||||
"timeTyping",
|
||||
"startedTests",
|
||||
"completedTests",
|
||||
],
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
banned: {
|
||||
$exists: false,
|
||||
[str + ".wpm"]: {
|
||||
$exists: true,
|
||||
},
|
||||
[str]: {
|
||||
$elemMatch: {
|
||||
language: "english",
|
||||
difficulty: "normal",
|
||||
timestamp: {
|
||||
$exists: true,
|
||||
},
|
||||
},
|
||||
[str + ".acc"]: {
|
||||
$exists: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceWith: {
|
||||
name: "$name",
|
||||
uid: "$uid",
|
||||
result: "$" + str,
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: "$result",
|
||||
},
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
"result.language": language,
|
||||
"result.difficulty": "normal",
|
||||
"result.punctuation": false,
|
||||
},
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
"result.name": "$name",
|
||||
"result.uid": "$uid",
|
||||
[str + ".uid"]: "$uid",
|
||||
[str + ".name"]: "$name",
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: "$result",
|
||||
newRoot: "$" + str,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue