流星集合无法访问(“未定义”)

时间:2016-04-08 10:29:00

标签: mongodb meteor collections

我试图获得一个名为cronHistory的集合的可见性(https://github.com/percolatestudio/meteor-synced-cron的一部分似乎运行正常)。

在流星外壳(服务器端)中,我可以看到其中包含的集合,例如:我的events集合:

> Meteor.Collection.getAll()

[{ name: 'events',
    instance:
     { _makeNewID: [Function],
       _transform: null,
       _connection: [Object],
       _collection: [Object],
       _name: 'events',
       _driver: [Object],
       _restricted: true,
       _insecure: undefined,
       _validators: [Object],
       _prefix: '/events/',
       before: [Object],
       _hookAspects: [Object],
       after: [Object],
       hookOptions: [Object],
       direct: [Object],
       _c2: [Object] },
    options: undefined },

...

 { name: 'cronHistory',
    instance:
     { _makeNewID: [Function],
       _transform: null,
       _connection: [Object],
       _collection: [Object],
       _name: 'cronHistory',
       _driver: [Object],
       _restricted: false,
       _insecure: undefined,
       _validators: [Object],
       _prefix: '/cronHistory/',
       before: [Object],
       _hookAspects: [Object],
       after: [Object],
       hookOptions: [Object],
       direct: [Object] },
    options: undefined } ]

但我无法从shell(或其他地方)访问它:

> cronHistory.findOne()
ReferenceError: cronHistory is not defined
    at [object Object]:1:-61
    at Script.(anonymous function) [as runInThisContext] (vm.js:41:22)
    at /Users/technical/code/mssc/.meteor/local/build/programs/server/shell-server.js:305:27
    at /Users/technical/.meteor/packages/meteor-tool/.1.1.10.1vct6fi++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/meteor-promise/fiber_pool.js:33:40

其他系列并非如此:

> FutureNotifications.findOne()
{ _id: 'btX6XGnXtaCkaEBzB' }
> Events.findOne()
{ _id: 'r3sw6kw9M8fPXGmvd',
  name: 'rstierstnrstrst',
  location: 'rein',

我该如何访问它?谢谢!

1 个答案:

答案 0 :(得分:1)

包存储在全局Package数组中。您可以使用Package["percolate:synced-cron"]访问Meteor shell中的包内部。

source code中挖了一分钟之后,这可能就是你想要的了:

Package["percolate:synced-cron"].SyncedCron._collection.findOne();

请注意,您也可以在浏览器控制台中访问Package,然后它会存储客户端软件包。显然,你应该只为了调试目的。