使用节点 ddp-client 从节点插入流星集合 [英] Using node ddp-client to insert into a meteor collection from Node

查看:11
本文介绍了使用节点 ddp-client 从节点插入流星集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 node.js 将一些系统日志数据流式传输到 Meteor 集合中.它工作正常,但是 ~10 秒的 Meteor 客户端轮询周期对于我的口味来说太长了 - 我希望它是 ~1 秒.

I'm trying to stream some syslog data into Meteor collections via node.js. It's working fine, but the Meteor client polling cycle of ~10sec is too long of a cycle for my tastes - I'd like it be be ~1 second.

通过控制台插入客户端集合很快,所有客户端都会立即更新,因为它使用的是 DDP.但是从服务器端直接插入 MongoDB 会受制于客户端的轮询周期.

Client-side collection inserts via console are fast and all clients update instantly, as it's using DDP. But a direct MongoDB insert from the server side is subject to the polling cycle of the client(s).

所以现在看来​​我只能使用 DDP 从我的节点守护程序插入更新.

So it appears that for now I'm relegated to using DDP to insert updates from my node daemon.

在 ddp-client 包示例中,我能够看到我订阅的消息,但我看不到如何通过 DDP 将消息实际发送到 Meteor 集合中,并且node.js,从而一次更新所有客户端...

In the ddp-client package example, I'm able to see messages I've subscribed to, but I don't see how to actually send new messages into the Meteor collection via DDP and node.js, thereby updating all of the clients at once...

有什么例子或指导吗?我将不胜感激 - 作为 node 和 Meteor 的新手,我很快就达到了自己的极限.

Any examples or guidance? I'd greatly appreciate it - as a newcomer to node and Meteor, I'm quickly hitting my limits.

推荐答案

根据 this截屏 可以简单地调用集合声明的meteor-methods.在您的情况下,代码如下所示:

According to this screencast its possible to simply call the meteor-methods declared by the collection. In your case the code would look like this:

ddpclient.call('/counts/insert', [{hits: 1111}], function(err, result) {
    console.log('called function, result: ' + result);
})

这篇关于使用节点 ddp-client 从节点插入流星集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆