以下是数据库查询(Express + RethinkDB)...
app.get('/projects', function(req, res) {
r.db("test").table("feeds").run(rdb)
.finally(function() { rdb.close()
}).then(function(cursor) {
return cursor.toArray()
}).then(function(output) {
res.send(output)
}).error(function(err) {
console.log("Error:", err)
})
})
...输出:[Object, Object]
我想删除一步(then()
),所以我写道:
app.get('/projects', function(req, res) {
r.db("test").table("feeds").run(rdb)
.finally(function() { rdb.close()
}).then(function(cursor) {
res.send(cursor.toArray())
}).error(function(err) {
console.log("Error:", err)
})
})
但是现在我得到一个布尔值而不是一个对象数组:
Invalid prop: type check failed. Expected Object, got Boolean.
我做错了什么部分?
答案 0 :(得分:1)
cursor.toArray()
不是同步操作。 This answer可能会提供一些见解。如果使用官方驱动程序,则必须像在第一个示例中那样将光标变为数组。
我个人使用rethinkdbdash来避免每次都手动执行此操作。