Accessing a collection created by a package


#1

So I am using percolate:synced-cron package and I want to gain access to the collection. How do I do that ?

The collection name I set was cronHistory.

And I am trying to use the following code

conHistory.find({}).

But I am not able to get it work.

Any advice ?


#2

if it’s not the spelling mistake on the collection name (conHistory), you need to explicitly export the variable name cronHistory in your package.js. Docs here, but would essentially be api.export(‘cronHistory’).


#3

I looked at percolate:synced-cron package.js which has

api.export(‘SyncedCron’, ‘server’);

Based on that, I am trying to use the following

SyncedCron.cronHistory.find

still no luck!


#4

Figured it out, tried this

Package[“percolate:synced-cron”].SyncedCron._collection.find


#5

I have the same issue. How the heck can you gain access to the cronHistory collection??

Package[“percolate:synced-cron”].SyncedCron._collection.find just gives

TypeError: Cannot read property ‘find’ of undefined


#6

Did you try:

import {SyncedCron} from 'meteor/percolate:synced-cron';
Meteor.startup(() => {
  SyncedCron._collection.find(); 
});

This works on my side. The mongo collection is just part of the SyncedCron object. Importing it means you will have the collection aswell

Edit
Make sure that you rum your code in a Meteor.startup block. The SyncedCron package only adds the collection on startup not on initialization kf the package.


#7

If I put your code in /server.main.js (and console.log the output)

import {SyncedCron} from ‘meteor/percolate:synced-cron’;
Meteor.startup(() => {
console.log(SyncedCron._collection.find({_id: 1}));
});

I get

{ _mongo:
I20171102-13:25:53.900(1)? { _observeMultiplexers: { ‘{“ordered”:false,“collectionName”:“usersSessions”,“selector”:{},“options”:{“transform”:null}}’: [Object] },
I20171102-13:25:53.901(1)? _onFailoverHook: { nextCallbackId: 1, callbacks: [Object], bindEnvironment: true },
I20171102-13:25:53.902(1)? db:
I20171102-13:25:53.903(1)? EventEmitter {
I20171102-13:25:53.905(1)? domain: null,
I20171102-13:25:53.906(1)? _events: {},
I20171102-13:25:53.908(1)? _eventsCount: 0,
I20171102-13:25:53.909(1)? _maxListeners: undefined,
I20171102-13:25:53.911(1)? s: [Object],
I20171102-13:25:53.912(1)? serverConfig: [Getter],
I20171102-13:25:53.914(1)? bufferMaxEntries: [Getter],
I20171102-13:25:53.915(1)? databaseName: [Getter] },
I20171102-13:25:53.917(1)? _primary: ‘127.0.0.1:3001’,
I20171102-13:25:53.920(1)? _oplogHandle:
I20171102-13:25:53.928(1)? { _oplogUrl: ‘mongodb://127.0.0.1:3001/local’,
I20171102-13:25:53.931(1)? _dbName: ‘meteor’,
I20171102-13:25:53.932(1)? _oplogLastEntryConnection: [Object],
I20171102-13:25:53.934(1)? _oplogTailConnection: [Object],
I20171102-13:25:53.940(1)? _stopped: false,
I20171102-13:25:53.942(1)? _tailHandle: [Object],
I20171102-13:25:53.944(1)? _readyFuture: [Object],
I20171102-13:25:53.945(1)? _crossbar: [Object],
I20171102-13:25:53.948(1)? _baseOplogSelector: [Object],
I20171102-13:25:53.949(1)? _catchingUpFutures: [],
I20171102-13:25:53.949(1)? _lastProcessedTS: [Object],
I20171102-13:25:53.950(1)? _onSkippedEntriesHook: [Object],
I20171102-13:25:53.951(1)? _entryQueue: [Object],
I20171102-13:25:53.952(1)? _workerActive: false },
I20171102-13:25:53.952(1)? _docFetcher: { _mongoConnection: [Circular], _callbacksForCacheKey: {} } },
I20171102-13:25:53.953(1)? _cursorDescription:
I20171102-13:25:53.954(1)? { collectionName: ‘cronHistory’,
I20171102-13:25:53.955(1)? selector: { _id: 1 },
I20171102-13:25:53.956(1)? options: { transform: null } },
I20171102-13:25:53.957(1)? _synchronousCursor: null }

Is this correct? What do I do to retrieve actual data? How do I query this collection? I don’t get it.