如何从 RethinkDB 文档中删除密钥? [英] How to remove a key from a RethinkDB document?

查看:65
本文介绍了如何从 RethinkDB 文档中删除密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 RethinkDB 文档中删除一个键.我的方法(不起作用):

I'm trying to remove a key from a RethinkDB document. My approaches (which didn't work):

r.db('db').table('user').replace(function(row){delete row["key"]; return row}) 

其他方法:

r.db('db').table('user').update({key: null}) 

这个只是设置了 row.key = null(看起来很合理).

This one just sets row.key = null (which looks reasonable).

通过 Web UI 在 rethinkdb 数据浏览器上测试的示例.

Examples tested on rethinkdb data explorer through web UI.

推荐答案

以下是 RethinkDB 网站文档中的相关示例:http://rethinkdb.com/docs/cookbook/python/#removing-a-field-from-a-document

Here's the relevant example from the documentation on RethinkDB's website: http://rethinkdb.com/docs/cookbook/python/#removing-a-field-from-a-document

要从表中的所有文档中删除一个字段,您需要使用 replace 更新文档以不包括所需的字段(使用 without):

To remove a field from all documents in a table, you need to use replace to update the document to not include the desired field (using without):

r.db('db').table('user').replace(r.row.without('key'))

要从表格中的一个特定文档中删除字段:

To remove the field from one specific document in the table:

r.db('db').table('user').get('id').replace(r.row.without('key'))

您可以使用 API 中的任何选择器更改要更新的文档选择 (http://rethinkdb.com/api/),例如dbtablegetget_allbetweenfilter.

You can change the selection of documents to update by using any of the selectors in the API (http://rethinkdb.com/api/), e.g. db, table, get, get_all, between, filter.

这篇关于如何从 RethinkDB 文档中删除密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆