Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript MeteorJS-没有用户系统,如何在客户端过滤数据?_Javascript_Mongodb_Meteor - Fatal编程技术网

Javascript MeteorJS-没有用户系统,如何在客户端过滤数据?

Javascript MeteorJS-没有用户系统,如何在客户端过滤数据?,javascript,mongodb,meteor,Javascript,Mongodb,Meteor,标题听起来可能很奇怪,但我有一个网站,可以查询Mongo收藏中的一些数据。但是,没有用户系统(没有登录等)。每个人都是匿名用户 问题是,我需要根据用户提供的输入文本框查询Mongo集合中的一些数据。因此,我不能使用this.userId插入一行规范,服务器端读取该规范,并将数据发送到客户端 因此: // Code ran at the server if (Meteor.isServer) { Meteor.publish("comments", function () {

标题听起来可能很奇怪,但我有一个网站,可以查询Mongo收藏中的一些数据。但是,没有用户系统(没有登录等)。每个人都是匿名用户

问题是,我需要根据用户提供的输入文本框查询Mongo集合中的一些数据。因此,我不能使用this.userId插入一行规范,服务器端读取该规范,并将数据发送到客户端

因此:

// Code ran at the server
if (Meteor.isServer)
{
    Meteor.publish("comments", function ()
    {
        return comments.find();
    });
}

// Code ran at the client
if (Meteor.isClient)
{
    Template.body.helpers
    (
        {
            comments: function ()
            {
                return comments.find()
                // Add code to try to parse out the data that we don't want here
            }
        }
    );
}
在用户端,我可能会根据一些用户输入过滤一些数据。但是,如果我使用
return comments.find()
服务器将向客户端发送大量数据,那么客户端将承担清理数据的工作

根据大量数据,应该不会有太多(10000行),但让我们假设有一百万行,我应该怎么做


我是MeteorJS的新手,刚刚完成教程,任何建议都非常感谢

我的建议是尤其要阅读文档

通过将上面发布函数的签名更改为带有参数的签名,可以在服务器上筛选集合,并将传输的数据限制为所需的数据

Meteor.publish("comments", function (postId)
{
    return comments.find({post_id: postId});
});
然后在客户机上,您需要一个subscribe调用来传递参数的值

Meteor.subscribe("comments", postId)

请确保已删除该软件包,否则它将忽略此筛选。

谢谢!我会尽快试试这个