Im trying filter records with that has a specific value key and delete them. I tried "withFields" and "hasFields" but seems that i can't apply delete to them. My question is how can i do that?
我尝试使用具有特定值键的过滤器记录并删除它们。我试过“withFields”和“hasFields”,但似乎我不能对它们应用删除。我的问题是我该怎么做?
2 个解决方案
#1
r.db('databaseFoo').table('checkpoints').filter(function (user) {
return user('type').default(false);
}).delete();
#2
If you want all documents that have a type
key, you can use hasFields
for that.
如果您想要所有具有类型键的文档,可以使用hasFields。
r.db('databaseFoo').table('checkpoints')
.hasFields('type')
In your current query, what you are doing is getting all documents that don't have a type
key or where the value for type
is equal to false
. This might be what you want, but it's a little confusing if you only want documents that have a type
property.
在当前查询中,您正在执行的操作是获取所有没有类型键的文档或类型值等于false的文档。这可能是您想要的,但如果您只想要具有type属性的文档,则会有点混乱。
Keeping a reference to the original document
保持对原始文档的引用
The problem with using hasFields
is that it converts a selection (a sequence with a reference to the specific rows in the database) that you can update
, and delete
into a sequence, with which you can't do that. This is a known issue in RethinkDB. You can read this blog post to understand the different types in ReQL a bit better.
使用hasFields的问题在于它会转换一个可以更新的选择(一个引用数据库中特定行的引用的序列),并将其删除为一个序列,您无法使用该序列执行此操作。这是RethinkDB中的已知问题。您可以阅读此博文,以更好地了解ReQL中的不同类型。
In order to get around this, you can use the hasFields
method with the filter
method.
为了解决这个问题,您可以将hasFields方法与filter方法一起使用。
r.db('databaseFoo').table('checkpoints')
.filter(r.row.hasFields('type'))
.delete()
This query will work since it returns a selection which can then be passed into delete
.
此查询将起作用,因为它返回一个选择,然后可以将其传递给delete。
If you want to get all records with with a specific value at a specific key, you can do so a couple of different ways. To get all documents where the property type
is equal to false
, you can do as follows:
如果要获取具有特定键的特定值的所有记录,可以采用几种不同的方式。要获取属性类型等于false的所有文档,您可以执行以下操作:
r.db('databaseFoo').table('checkpoints')
.filter({ type: false })
or, you can do:
或者,你可以这样做:
r.db('databaseFoo').table('checkpoints')
.filter(r.row('type').eq(false))
#1
r.db('databaseFoo').table('checkpoints').filter(function (user) {
return user('type').default(false);
}).delete();
#2
If you want all documents that have a type
key, you can use hasFields
for that.
如果您想要所有具有类型键的文档,可以使用hasFields。
r.db('databaseFoo').table('checkpoints')
.hasFields('type')
In your current query, what you are doing is getting all documents that don't have a type
key or where the value for type
is equal to false
. This might be what you want, but it's a little confusing if you only want documents that have a type
property.
在当前查询中,您正在执行的操作是获取所有没有类型键的文档或类型值等于false的文档。这可能是您想要的,但如果您只想要具有type属性的文档,则会有点混乱。
Keeping a reference to the original document
保持对原始文档的引用
The problem with using hasFields
is that it converts a selection (a sequence with a reference to the specific rows in the database) that you can update
, and delete
into a sequence, with which you can't do that. This is a known issue in RethinkDB. You can read this blog post to understand the different types in ReQL a bit better.
使用hasFields的问题在于它会转换一个可以更新的选择(一个引用数据库中特定行的引用的序列),并将其删除为一个序列,您无法使用该序列执行此操作。这是RethinkDB中的已知问题。您可以阅读此博文,以更好地了解ReQL中的不同类型。
In order to get around this, you can use the hasFields
method with the filter
method.
为了解决这个问题,您可以将hasFields方法与filter方法一起使用。
r.db('databaseFoo').table('checkpoints')
.filter(r.row.hasFields('type'))
.delete()
This query will work since it returns a selection which can then be passed into delete
.
此查询将起作用,因为它返回一个选择,然后可以将其传递给delete。
If you want to get all records with with a specific value at a specific key, you can do so a couple of different ways. To get all documents where the property type
is equal to false
, you can do as follows:
如果要获取具有特定键的特定值的所有记录,可以采用几种不同的方式。要获取属性类型等于false的所有文档,您可以执行以下操作:
r.db('databaseFoo').table('checkpoints')
.filter({ type: false })
or, you can do:
或者,你可以这样做:
r.db('databaseFoo').table('checkpoints')
.filter(r.row('type').eq(false))