Change primary key from "id" to "any_other_key"

473 Views Asked by At

How can I change primary key of RethinkDB after my rethinkdb feathers service is created?

I tried below code but it won't affect.

app.use('/messages', service({
  id: 'user_id',
  Model: db,
  name: 'messages'
}));

Is there anything I missed?

1

There are 1 best solutions below

1
Daff On

When using a different primary key the RethinkDB database needs to be initialized with the same primaryKey option. You can either do that manually or use service.init as documented here:

// Initialize the `messages` table with `user_id` as the primary key
app.service('messages').init({
  primaryKey: 'user_id'
}).then(() => {
  // Use service here
});