【发布时间】:2014-10-01 15:34:51
【问题描述】:
// in server.js
Meteor.publish("directory", function () {
return Meteor.users.find({}, {fields: {emails: 1, profile: 1}});
});
// in client.js
Meteor.subscribe("directory");
我现在想从浏览器的控制台获取从客户端查询的目录列表,例如directory.findOne()。 //测试目的
执行directory=Meteor.subscribe('directory')/directory=Meteor.Collection('directory') 和执行directory.findOne() 不起作用,但是当我执行directory=new Meteor.Collection('directory') 时它起作用并返回未定义,我敢打赌它会在服务器上创建一个我不喜欢的mongo 集合,因为USER 集合已经存在,它指向一个新的集合而不是 USER 集合。
注意:我不想弄乱 Meteor.users 集合如何处理其功能...我只想使用不同的句柄从中检索一些特定数据,该句柄只会返回指定的字段而不是覆盖其默认值函数...
例如:
Meteor.users.findOne() // will return the currentLoggedIn users data
directory.findOne() // will return different fields taken from Meteor.users collection.
【问题讨论】:
-
这应该是
directory = new Meteor.Collection('directory')。如果它是未定义的,那么你可能在其他地方分配了这个变量。 -
我想使用“目录”作为句柄从 Meteor.users 集合中获取数据,如果我这样做 new Meteor.Collection("directory") 不会创建一个 mongo 集合到服务器端并将“目录”句柄附加到“目录集合”?
-
尝试将新的 Meteor.Collection('directory') 放到客户端专用文件夹中(在服务器和客户端都读取之前),但仍然无效。
-
啊...现在我知道你在那里做了什么:)