gpt4 book ai didi

javascript - MeteorJS 发布查询不起作用

转载 作者:行者123 更新时间:2023-12-03 08:50:56 26 4
gpt4 key购买 nike

我尝试将 Meteor.publish (服务器端)与此查询一起使用:

return Meteor.users.find({_id:{$ne:this.userId}});

当我在客户端使用 Meteor.subscribe 进行查询时,它有效:

return Meteor.users.find({_id:{$ne:Meteor.userId()}});

那么为什么它在服务器端不起作用...似乎我只能在客户端查询一次...问题是,我不想下载整个集合,因为我将有超过20,000 个用户。发布方法是否不允许“$”查询?

另外,我如何将其附加到我的以下查询语句中:

return Meteor.users.find({"profile.loc":{ $near: [ to[0].profile.loc.lat, to[0].profile.loc.lon ], $maxDistance: (1/111.2)*250}});

最佳答案

正如上面的答案所述,如果您按照您所写的操作,您无论如何都会发布 19,999 个用户。

不过,您的问题分为两部分,您实际上应该通过一个查询来解决这两部分:为此,您应该有一个带有参数的出版物:

    Meteor.publish('users', function(location) { 
return Meteor.users.find(
{_id: {$ne: this.userId},
"profile.loc":{
$near: [ location.lat, location.lon ],
$maxDistance: (1/111.2)*250}
}
});

这将筛选服务器上符合位置条件的用户。

在客户端,您可以通过以下方式订阅它:

location = {lon: 12.123, lat: 110.2};
Meteor.subscribe('users', location);

或您选择的对象。

关于javascript - MeteorJS 发布查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32676655/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com