Gary Sieling

RethinkDB: Fixing error “e: Object field ‘Title’ may not be undefined”

If you access data values incorrectly, you may get an error like so:

Object field 'Title' may not be undefined

Here is an example of what not to do:

r.db('test')
 .table('salaries')
 .group('role', 'level')
 .sum('salary')
 .ungroup()
 .map( (x) => {
    return {
    Title: x('group')[0],
    Level: x('group')[1],
    Value: x('reduction')
}})

Remember that RethinkDB wants you to access everything through function calls, since it needs this for cross-language support. To fix this error, you access the arrays with function calls, like so:

r.db('test')
 .table('salaries')
 .group('role', 'level')
 .sum('salary')
 .ungroup()
 .map( (x) => {
    return {
    Title: x('group')(0),
    Level: x('group')(1),
    Value: x('reduction')
}})
Exit mobile version