我是rethinkdb的新手。 当我在https://github.com/rethinkdb/rethinkdb-example-nodejs/tree/master/todo-angular-express
中试用示例代码时function create(req, res, next) {
var todo = req.body;
todo.createdAt = r.now(); // Set the field `createdAt` to the current time
r.table('todos').insert(todo, {returnVals: true}).run(req._rdbConn, function(error, result) {
if (error) {
handleError(res, error)
}
else if (result.inserted !== 1) {
handleError(res, new Error("Document was not inserted."))
}
else {
res.send(JSON.stringify(result.new_val));
}
next();
});
}
我收到以下错误:
500内部服务器错误
{"错误":" return_vals重命名为return_changes:\ nr.table(\" todos \")。insert({title:r.json( \" \" abcde \" \"),已完成:r.json(\" false \"),createdAt:r.now()} ,{returnVals:true})\ n
然后我尝试了http://rethinkdb.com/docs/examples/node-todo/
中的示例代码function create(req, res, next) {
var todo = req.body; // req.body was created by `bodyParser`
todo.createdAt = r.now(); // Set the field `createdAt` to the current time
r.table('todos').insert(todo, {returnChanges: true}).run(req._rdbConn, function(error, result) {
if (error) {
handleError(res, error)
}
else if (result.inserted !== 1) {
handleError(res, new Error("Document was not inserted."))
}
else {
res.send(JSON.stringify(result.changes[0].new_val));
}
next();
});
}
我收到以下错误:
500内部服务器错误 {"错误":"无法识别的可选参数
returnChanges
。 in:\ nr.table(\" todos \")。insert({title:r.json(\" \" abcde \" \" ),完成:r.json(\" false \"),createdAt:r.now()},{returnChanges:true})\ n"}
似乎rethinkdb已将 returnVals 更改为 return_changes / returnChanges ,以及insert()的参数。
当我使用 return_changes 时,我解决了问题。
在最新版本中插入工作的正确方法是什么? rethinkdb是否总是更改其语法?
答案 0 :(得分:1)
这确实是示例代码中的错误。我已经打开了https://github.com/rethinkdb/rethinkdb-example-nodejs/issues/3,所以我们可以解决它。
returnChanges
未被识别的第二个问题可能来自使用旧的RethinkDB节点驱动程序。您是否尝试过更新驱动程序? http://rethinkdb.com/docs/install-drivers/javascript/