【问题标题】:meteor subscribe/publish with parameter return 0流星订阅/发布参数返回 0
【发布时间】:2014-02-26 17:14:00
【问题描述】:

我现在正在学习订阅和发布。 这是我在客户端的 subscribe.js

var userhandle = null;

Deps.autorun(function () {
    userhandle = Meteor.subscribe('user', 1);
    if(userhandle.ready()){
    console.log("ready");
    }

});

这是我在服务器上的 publish.js

Meteor.publish('user', function (amount) {

    return Users.find({
        limit: amount
    });
});

我希望我可以根据需要发布“用户”数据。

在我运行这个之后,没有任何错误,我做到了

Users.find().fetch()

在浏览器控制台上,但它返回 0 长度 为什么会这样? 如何使它工作?

更新: 我不使用meteor.users 我只是使用简单的集合 用户 = new Meteor.collection("USER");

【问题讨论】:

  • 来自accounts 包的用户集合是Meteor.users。你在哪里定义 Users 集合?
  • 我不使用 Meteor.users 只是简单的收集
  • 这可能是一个很大的安全问题。 Meteor 的帐户包使用称为Secure Remote Password 的可靠、安全的协议。您是否以明文形式传输或存储密码?

标签: javascript meteor


【解决方案1】:

您在发布函数中的 find 查询格式不正确 - 如果您指定选项,则需要一个查询对象,即使它是空的:

return Users.find({}, {
    limit: amount
});

试一试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-04
    • 2014-06-16
    • 2015-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-29
    • 2018-12-18
    相关资源
    最近更新 更多