0

我正在编写自己的包,我需要依赖dburles:mongo-collection-instances. 我知道集合实例包会修改Mongo.Collection对象,但我看不到Mongo.Collection.getAll()在我的自定义包中使用。

var collections = Mongo.Collection.getAll(); // Doesn't work
console.log('collections', collections);

我的package.js

Package.onUse(function(api) {
  api.versionsFrom('1.0.3.1');
  api.use('jquery');
  api.use('mongo');
  api.use('session');
  api.use('matb33:collection-hooks');
  api.use('dburles:mongo-collection-instances');
  api.use('accounts-base', ['client', 'server'], {weak: true});
...
});
4

1 回答 1

0

不确定你是如何构建你的包的?我没有使用 dburles 集合实例,但这是一种正确的结构方式:

/packagefolder
 both.js
 package.js

在你的package.js

Package.describe({
summary: 'mycollection collection',
  name: 'mycollection:mycollection',
  version: '0.0.1'
});

Package.onUse(function (api) {
  api.use('jquery');
  api.use('mongo');
  api.use('session');
  api.use('matb33:collection-hooks');
  api.use('dburles:mongo-collection-instances');
  api.use('accounts-base', ['client', 'server'], {weak: true});

  api.addFiles([
    'both.js'
  ], ['server', 'client']);

  api.export('MyCollection');
});

我推荐 aldeed 收集包.. 这是一个both.js演示

MyCollection = new Mongo.Collection('mycollection');

Schemas = {};
Schemas.MyCollection = new SimpleSchema({
  profileId: {
    type: String
  },
  date: {
    type: Date
  }
});

MyCollection.attachSchema(Schemas.MyCollection);
于 2016-06-25T18:30:07.127 回答