Hi there,
I’m actually trying to build a Meteor global function, which will crawl every collections i have to see if a field / key (SimpleSchema) have a specific property i added.
For this, i did this :
var collections = Mongo.Collection.getAll();
collections.forEach((col) => {
function getSchema(col) {
var col = col.name;
if (col != null) {
return col.charAt(0).toUpperCase() + col.slice(1) + 'Schema';
} else {
col = null;
return col;
}
}
if (typeof col !== 'undefined' && typeof col !== null) {
console.log(getSchema(col));
// console.log(getSchema(col).get('partners_id', 'label'));
}
});
In this example, i’m trying to display my collections at the end, it works, and i can see all :
MeteorToys.ImpersonateSchema
MeteorToys.JetSetterSchema
MeteorToys.MongolSchema
MeteorToys.AutoPubSchema
… and so on …
Perhaps, the commented part : " // console.log(getSchema(col).get(‘partners_id’, ‘label’));" tell me :
“Exception in defer callback: TypeError: getSchema(…).get is not a function”.
Is there any way to complete this ?
I tried :
var collections = Mongo.Collection.getAll();
collections.forEach((col) => {
function getSchema(col) {
var col = col.name;
// console.log(col.charAt(0).toUpperCase() + col.slice(1) + 'Schema');
if (col != null) {
return col.charAt(0).toUpperCase() + col.slice(1) + 'Schema';
} else {
col = null;
return col;
}
}
if (typeof col !== 'undefined' && typeof col !== null) {
try {
// console.log(getSchema(col));
console.log(getSchema(col).get('partners_id', 'label'));
} catch (error) {
console.log(error + ' : For collection : ' + getSchema(col.name));
}
}
});
But i’m having :
7crm.js:42 TypeError: getSchema(…).get is not a function : For collection : null
meteor.js?hash=0504f43f667698535416b00eb44eb6f53161cb63:1050 Exception in defer callback: TypeError: Cannot read property ‘name’ of null
at getSchema (crm.js:28)
at crm.js:42
at Array.forEach ()
at Blaze.TemplateInstance. (crm.js:26)
at blaze.js?hash=adc5286b78e5c0f8e7f56a602f77eefb5def6bf1:3398
at Function.Template._withTemplateInstanceFunc (blaze.js?hash=adc5286b78e5c0f8e7f56a602f77eefb5def6bf1:3769)
at fireCallbacks (blaze.js?hash=adc5286b78e5c0f8e7f56a602f77eefb5def6bf1:3394)
at Blaze.View. (blaze.js?hash=adc5286b78e5c0f8e7f56a602f77eefb5def6bf1:3474)
at fireCallbacks (blaze.js?hash=adc5286b78e5c0f8e7f56a602f77eefb5def6bf1:2014)
at Object.Tracker.nonreactive (tracker.js:603)
I don’t know why it’s not working. Can’t see what i missed. Any ideas ?
Happy coding,
B.