RethinkDB如何删除列表中除最新值之外的重复值

RethinkDB how to delete duplicated values in a list except for the latest value

如果有重复的 title,我想减少 adbKeys 的列表。 我想在列表中保留最新或最后的值。

Query: r.db('stf').table('users').filter(r.row('adbKeys').count().gt(5))('adbKeys')

结果:

[
    [{
        "adbKeys": [{
            "fingerprint": "1111",
            "title": "lus@344.local"
        }, {
            "fingerprint": "1111",
            "title": "@bbbbb"
        }, {
            "fingerprint": "2222",
            "title": "@bbbbb"
        }, {
            "fingerprint": "4444",
            "title": "@aaaaa"
        }, {
            "fingerprint": "5555",
            "title": "@aaaaa"
        }, {
            "fingerprint": "6666",
            "title": "@aaaaa"
        }, {
            "fingerprint": "7777",
            "title": "@aaaaa"
        }, {
            "fingerprint": "8888",
            "title": "@aaaaa"
        }]
    }]
]

所以我想删除查询用户中的以下值:

[{
        "fingerprint": "1111",
        "title": "@bbbbb"
    },
    {
        "fingerprint": "4444",
        "title": "@aaaaa"
    }, {
        "fingerprint": "5555",
        "title": "@aaaaa"
    }, {
        "fingerprint": "6666",
        "title": "@aaaaa"
    }, {
        "fingerprint": "7777",
        "title": "@aaaaa"
    }
]

如果您需要了解 table。

r.db('stf').table('users').get('xxxxxxxx')

看起来像:

{
    "adbKeys": [{
        "adbKeys": [{
            "fingerprint": "1111",
            "title": "lus@344.local"
        }, {
            "fingerprint": "1111",
            "title": "@bbbbb"
        }, {
            "fingerprint": "2222",
            "title": "@bbbbb"
        }, {
            "fingerprint": "4444",
            "title": "@aaaaa"
        }, {
            "fingerprint": "5555",
            "title": "@aaaaa"
        }, {
            "fingerprint": "6666",
            "title": "@aaaaa"
        }, {
            "fingerprint": "7777",
            "title": "@aaaaa"
        }, {
            "fingerprint": "8888",
            "title": "@aaaaa"
        }]
    }],
    "createdAt": {
        "$reql_type$": "TIME",
        "epoch_time": 1601271054.923,
        "timezone": "+00:00"
    },
    "email": "xxxxxxxx",
    "forwards": [],
    "group": "xxxxxxx",
    "groups": {
        "lock": false,
        "quotas": {
            "allocated": {
                "duration": 12960000000,
                "number": 5
            },
            "consumed": {
                "duration": 0,
                "number": 2
            },
            "defaultGroupsDuration": 1296000000,
            "defaultGroupsNumber": 5,
            "defaultGroupsRepetitions": 10,
            "repetitions": 10
        },
        "subscribed": ["213123", "123123123"]
    },
    "ip": "44.33.11.22"
}

我正在使用以下查询,它并不完美,但有效。

r.db('stf').table('users').filter(r.row('adbKeys').count().ge(20)).update({'adbKeys': r.row("adbKeys").slice(18)}).run(conn)