不能使用其他Meteor软件包中的其他Meteor软件包

时间:2016-06-25 12:33:35

标签: mongodb meteor meteor-packages

我正在编写自己的包,我需要依赖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});
...
});

1 个答案:

答案 0 :(得分: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 collection package ..这里是both.js演示

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

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

MyCollection.attachSchema(Schemas.MyCollection);