解析实时查询不起作用?

时间:2018-06-16 01:08:16

标签: javascript parse-platform

我尝试设置解析实时查询,但由于某种原因它没有返回任何结果。

我可以从中提取数据,所以我知道服务器和数据库运行良好。

'打开'当我在localhost上运行时连接工作,但即使这样,也不会调用订阅事件。

客户端

var Parse = require('parse/node');

Parse.initialize("key", "", "pass");
Parse.serverURL = parseServer;
Parse.liveQueryServerURL = 'ws://localhost:1337/';


let query = new Parse.Query('groups');
query.equalTo('name', 'name');
let subscription = query.subscribe();


subscription.on('update', (people) => {
    console.log("YEAY");
  // console.log(people.get('score')); // This should output 100
});

subscription.on('open', () => {
    console.log('subscription opened');
});

服务器

var app = new ParseServer({
startLiveQueryServer: true,
  liveQuery: {
    classNames: ["groups", "comments"] // List of classes to support for query subscriptions
  },
..}

var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
    console.log('parse-server-example running on port ' + port + '.');
});

// This will enable the Live Query real-time server
var parseLiveQueryServer = ParseServer.createLiveQueryServer(httpServer);

1 个答案:

答案 0 :(得分:0)

您可以尝试更改此内容

let subscription = query.subscribe();

对此

let subscription = await query.subscribe();

希望有帮助。