TypeError: Collection.find is not a function


#1

Hi,

I have collection defined in /imports/api/ShopFloor/ShopFloor.js like this:

/* eslint-disable consistent-return */

import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';

const ShopFloor = new Mongo.Collection('ShopFloor');

ShopFloor.allow({
  insert: () => false,
  update: () => false,
  remove: () => false,
});

ShopFloor.deny({
  insert: () => true,
  update: () => true,
  remove: () => true,
});

ShopFloor.schema = new SimpleSchema({
  ProductionLotID: {
      type: String
    },
    createdAt: {
      type: String,
      label: 'The date this document was created.',
      autoValue() {
        if (this.isInsert) return (new Date()).toISOString();
      },
    },
    updatedAt: {
      type: String,
    },
    ProductionOrderID: {
      type: String,
    },
    ProductionOrderUUID: {
      type: String,
    },
    ProductionLotUUID: {
      type: String,
    },
    ProductionLotStatus: {
      type: String,
    },
    MainOutputProduct: {
      type: String,
    },
    ConfirmationGroupUUID: {
      type: String,
    },
    MaterialOutputUUID: {
      type: String
    }

  });
  
  ShopFloor.attachSchema(ShopFloor.schema);
  

export default ShopFloor;

Now i’m publishing it in api/ShopFloor/server/publications.js

import { Meteor } from 'meteor/meteor';
import ShopFloor from '../ShopFloor';

Meteor.publish('ShopFloor', function ShopFloor() {
  return ShopFloor.find();
});

In this publication im getting error:

TypeError: ShopFloor.find is not a function

What can be wrong? I can’t figure out…


#2

Found the problem.

In publish:

Meteor.publish('ShopFloor', function ShopFloor() {
  return ShopFloor.find();
});

the function ShopFloor overwrote the collection function and didn’t have any find method ofcourse.

Meteor.publish('ShopFloor', function shopFloor() {
  return ShopFloor.find();
});

Works fine…