RethinkDB中的复合主键

abi*_*ash 5 rethinkdb

我可以在RethinkDB中创建复合主键吗?例如,如果我有一个表与下一个文件结构{authorsId: '371df80c-2efd-48f9-ac37-3edcdb152fb1', postsId: '905e0c92-adcb-4095-98df-fa08ca71b900'},我怎么能在两个authorsId和同时创建主键postsId.或者,如果我不能这样做,我应该如何以三种方式使用多对多的关系.我是使用一个字段作为主键还是第二个作为二级索引?

Oli*_*ver 3

主键只能位于一列上,但您可以将postsId和放入authorsId数组中并将其用作主键值。

请参阅此处了解更多信息: https ://www.rethinkdb.com/api/javascript/table_create/

编辑

主键仍然只是一个字段,但您可以使用 [postsId,authorsId] 作为该列的值并实现相同的效果。(从评论中添加回答案)。

  • 我想答案是这样的。`r.db('test').tableCreate('mytable', {primaryKey: 'myprimary'})` 然后当您执行读取、插入或更新时 `r.db('test').table(' mytable').insert({myprimary: ['id1value', 'id2value'], othervalue: 'something'})` 和 `r.db('test').table('mytable').update({myprimary: ['id1value', 'id2value'], othervalue: 'newthing'})` 和 `r.db('test').table('mytable').get(['id1value', 'id2value'])`。在数据浏览器上测试 (2认同)