复合索引的 getAll 内部条件
Condition inside getAll for compound index
的等效查询是什么
select * from emails where to="someemail" and from="some@email"
需要使用 get 而不是 filter
getAll
是你的朋友:
table.getAll([key, key2...], [, {index:'id'}]) → selection
假设您有一个复合键索引,例如:
r.db('emails')
.table('emails')
.indexCreate('conversation', [r.row('from'), r.row('to')])
您可以轻松获取所有电子邮件:
r.db('emails')
.table('emails')
.getAll(['some@email', 'someemail'], {index: 'conversation'})
例如,有以下数据集
r.db('emails')
.table('emails')
.insert([
{from: 'foo@mail', to: 'bar@mail', text: 'Hi Bar!'},
{from: 'bar@mail', to: 'foo@mail', text: 'Hi Foo!'},
{from: 'foo@mail', to: 'bar@mail', text: 'Bye Bar!'},
{from: 'bar@mail', to: 'foo@mail', text: 'Bye Foo!'}
])
这是用以下查询查询的
r.db('emails')
.table('emails')
.getAll(['foo@mail', 'bar@mail'], {index: 'conversation'})
.pluck('text')
将产生:
[
{"text": "Bye Bar!"},
{"text": "Hi Bar!"}
]
(以上顺序未定义)
select * from emails where to="someemail" and from="some@email"
需要使用 get 而不是 filter
getAll
是你的朋友:
table.getAll([key, key2...], [, {index:'id'}]) → selection
假设您有一个复合键索引,例如:
r.db('emails')
.table('emails')
.indexCreate('conversation', [r.row('from'), r.row('to')])
您可以轻松获取所有电子邮件:
r.db('emails')
.table('emails')
.getAll(['some@email', 'someemail'], {index: 'conversation'})
例如,有以下数据集
r.db('emails')
.table('emails')
.insert([
{from: 'foo@mail', to: 'bar@mail', text: 'Hi Bar!'},
{from: 'bar@mail', to: 'foo@mail', text: 'Hi Foo!'},
{from: 'foo@mail', to: 'bar@mail', text: 'Bye Bar!'},
{from: 'bar@mail', to: 'foo@mail', text: 'Bye Foo!'}
])
这是用以下查询查询的
r.db('emails')
.table('emails')
.getAll(['foo@mail', 'bar@mail'], {index: 'conversation'})
.pluck('text')
将产生:
[
{"text": "Bye Bar!"},
{"text": "Hi Bar!"}
]
(以上顺序未定义)