Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
REJECTDB—文档中的整数增量(Python)_Python_Rethinkdb - Fatal编程技术网

REJECTDB—文档中的整数增量(Python)

REJECTDB—文档中的整数增量(Python),python,rethinkdb,Python,Rethinkdb,如何在文档中执行简单的整数增量(如果有)?我尝试了r.db(“test”).get(id).update({“views”:r.row.add(1)}).run(),但它不起作用 目前我是这样做的: m = r.db("test").get(id).run() r.db("test").get(id).update({"views":m["views"]+1}).run() 如果有一套解决方案,那就太好了。这应该可以: r.table("posts").get(1).update({

如何在文档中执行简单的整数增量(如果有)?我尝试了
r.db(“test”).get(id).update({“views”:r.row.add(1)}).run()
,但它不起作用

目前我是这样做的:

m = r.db("test").get(id).run()
r.db("test").get(id).update({"views":m["views"]+1}).run()
如果有一套解决方案,那就太好了。

这应该可以:

r.table("posts").get(1).update({
    views: r.row["views"].add(1)
})
您正在执行
r.row.add
操作,但需要选择要递增的字段(
视图,在本例中为
)。因此,您必须执行
r.row[“”]。添加(1)

这应该可以:

r.table("posts").get(1).update({
    views: r.row["views"].add(1)
})

您正在执行
r.row.add
操作,但需要选择要递增的字段(
视图,在本例中为
)。因此,您必须执行
r.row[“”].add(1)

我得到了错误r.row不可调用,使用r.row[…]而不是将其修复,它需要这样做
r.table(“posts”).get(1).update({views:r.row[“views”].add(1)})
我正在更新答案。我得到了错误r.row不可调用,使用r.row[…]而不是将其修复,需要这样做
r.table(“posts”).get(1).update({views:r.row[“views”].add(1)})
我正在更新答案。