【问题标题】:Meteor collection folder structure流星收藏文件夹结构
【发布时间】:2015-04-19 19:58:55
【问题描述】:

official Meteor doc 说:

Collections/#

在我的数据库中,我有一个集合 universities。所以在我的收藏文件夹中我有university.js。
如何实现集合上的方法,例如find()?我不想在我的index.js 中包含所有代码。我知道我可以拥有 Meteor.methods 和 Meteor.call 但那是用于客户端 - 服务器调用。

【问题讨论】:

  • find 会自动添加到所有集合实例中。您是指您的收藏更具体的内容吗?

标签: javascript mongodb meteor


【解决方案1】:

也许可以创建一个这样的函数。在您想要的任何文件夹上/lib/collections 都可以选择。

例如 find()

function findMethod(){
  return Collection.find();
}

随心所欲地使用它。

var finde = findMethod();

【讨论】:

  • 非常感谢。因此,如果我的数据库集合中已经有大学和 collections.js - University = new Mongo.Collection("university"),它会自动绑定吗?
  • 取决于你有没有自动发布包?如果你已经删除它,你应该使用 publish(server)/subscribe(client) 方法
  • 谢谢,我会检查这个答案。还有一个问题,我已经删除了 autopublish 包,在我的 serve/publications.js 我有 Meteor.publish('universities', function() { return University.find(); });在我的 application.js 文件中,我有 subscribe 方法。我的收藏只是第一次加载,刷新后,收藏就消失了。有什么收获?
  • 现在好了。谢谢你:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多