【发布时间】:2016-07-07 23:53:07
【问题描述】:
1.- 我正在使用 loopback-connector-rethinkdbdash
2.- 在远程方法上,我需要从我的数据库中检索一些随机记录,这是目前为止的代码。
(function(){
'use strict';
module.exports = (Heatmap) => {
var r = require('rethinkdb');
// Connect to RethinkDB
var p = r.connect({
host: 'rethink',
port: 28015,
db: 'livedata'
});
// Error Handler
function throwErr(err) {
throw (err);
}
// Random Remote Method
Heatmap.random = (cb) => {
p.then(function(conn) {
r.table('heatmap').run(conn, function(err, cursor) {
cursor.toArray(function(err, results) {
console.log('ALO-4', results)
cb(err, results);
})
})
}).error(throwErr);
}; // Heatmap.random
Heatmap.remoteMethod(
'random',
{
accepts : [],
returns : { arg : 'results', type : 'array', root : true },
http : { path : '/random', verb : 'get' }
}
); // Heatmap.remoteMethod
};
}).call(this);
3.- 我已经关注了这个文档:https://github.com/neumino/rethinkdbdash https://docs.strongloop.com/display/public/LB/Remote+methods#Remotemethods-Argumentdescriptions
4.- 问题是记录或结果会在 console.log('ALO-4') 上返回,但不会在浏览器中返回...
我不知道发生了什么,有人可以帮助我吗?
泰
【问题讨论】:
标签: node.js rethinkdb loopback