Search code examples
joinrethinkdbreql

Primary key too long with eqJoin in RethinkDB


I am trying to use joins in RethinkDB in a simple way.

This is the query I tried, like shown in the docs:

r.table('users')('inventory').default([]).eqJoin('name', r.table('prices')).without({
    right: 'name'
}).zip()

I have an item list for each user like this:

[
    {
        id: "user1",
        inventory: [
            {
                itemid: '1418676',
                name: 'foo'
            },
            {
                itemid: '2849',
                name: 'bar'
            }
        ]
    },
    {
        id: "user2",
        inventory: [
            {
                itemid: '98742',
                name: 'top'
            },
            {
                itemid: '6217',
                name: 'kek'
            }
        ]
    }
]

And a price table:

[
    {
        name: 'foo',
        price: 42
    },
    {
        name: 'bar',
        price: 41
    },
    {
        name: 'top',
        price: 40
    },
    {
        name: 'kek',
        price: 69
    }
]

But for some reasons the driver throws an error:

e: Primary key too long (max 127 characters): [
    "foo",
    "bar",
    "top",
    "kek",
    "and all the other items name"
]

Solution

  • r.table('users')('inventory') is a sequence of arrays, and so r.table('users')('inventory')('name') is an array of names, not a single name.

    Perhaps using concatMap will give the desired results. For example:

    r.table('users')
     .concatMap(r.row('inventory').default([]))
     .eqJoin('name', r.table('prices'))