1

我想减少adbKeys是否有重复的列表title。我想在列表中保留最新或最后一个值。

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"
    }
]

如果您需要了解该表。

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"
}
4

1 回答 1

0

我正在使用以下查询,这并不完美,但可以正常工作。

r.db('stf').table('users').filter(r.row('adbKeys').count().ge(20)).update({'adbKeys': r.row("adbKeys").slice(18)}).run(conn)
于 2020-12-21T05:36:37.333 回答