Undefined collection after adding Schema [collection2]

Hello there, I have a specific problem. I used MeteorKitchen, so some code could look worse than normal.

I installed collection2, because of yogiben:admin, and add a schema to my

Schemas.Invoicess = new SimpleSchema({

And when the code is done, I lose my collection on my page where I use that collection (collection is undefined).
The collection on page is named: “fakturka”.
Of course I did in:


Meteor.publish("fakturka", function(invoiceId) {
    return Invoices.find({_id:invoiceId,ownerId:this.userId}, {});


    Meteor.subscribe("fakturka", this.params.invoiceId),
fakturka: Invoices.findOne({_id:this.params.invoiceId}, {}),

When I comment my Schema, the “fakturka” is ready to be seen (defined), but when I add the schema, the “fakturka” is undefined. It’s only one collection I have problem with, because others work properly.
Is it ok that I use subcontest on that page? Because “normal” site path is client/views/invoices/new/new.html, and I have a subpage in that ( ./insert/insert.html)

Do you still have the

Invoices = Meteor.Collection('invoices');

Somewhere in your code? It’s still needed.

Then remember to attach the schema:


You’re also a little confused on terminology “fakturka” is a publication it is not a collection.

Publications publish a set of documents from a collection. You then subscribe to that set of documents with subscribe.

Yup, I have that thing in the same file (both/collections/invoices.js)

this.Invoices = new Mongo.Collection("invoices");

and of course I attach Schema after everything in the same file:


Oh, Ok. It’s publication - god to know :slight_smile:

What do you mean by this? Is there an error or is your Client Side collection not populated with the published document?

I open my site with Chrome and use extra panels. When I open a page and try to add some things (for example: item of an invoice), the “fakturka” is seen as undefined.
When my Schema is not declared, faktura is defined. I don’t know why.

I have a tree that looks like this

  • client
    – views
    — invoices
    ---- new
    ----- new.html
    ----- new.js
    ----- new_controller.js
    ----- edititem
    ------ edititem.html
    ------ edititem.js
    ------ edititem_controller.js
    ----- insert
    ------ insert.html
    ------ insert.js
    ------ insert_controller.js

Maybe that’s the problem?
When I want to add an invoice, I open “invoices.html”, than I click a button, which has route to "new :id"
And when I open that page I have subpages “insert”, in which I could insert my “items” to invoice.

Any ideas? I’m getting frustrated, because I don’t know why that bug exist :confused:

you should just have

Invoices = new Mongo.Collection('invoices');

without the this. in front. Because depending on where you’re calling that code, the this is making your collections declaration specific to that context where as you want it to be global.